Skip to main content

ARM Architecture and Programming

  • Chapter
  • First Online:
Embedded and Real-Time Operating Systems
  • 711 Accesses

Abstract

This chapter covers the ARM architecture, ARM instructions, ARM programming, and development of programs for execution on ARM virtual machines. These include ARM processor modes, register banks in different modes, instructions, and basic programming in ARM assembly. It introduces the ARM toolchain under Ubuntu (15.10) Linux and emulated ARM virtual machines under QEMU. It shows how to use the ARM toolchain to develop programs for execution on the ARM Versatilepb virtual machine by a series of programming examples. It explains the function call convention in C and shows how to interface assembly code with C programs. Then it develops a simple UART driver for I/O on serial ports and an LCD driver for displaying both graphic images and text. It also shows the implementation of a generic printf() function for formatted printing to output devices that support the basic print char operation.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 99.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Hardcover Book
USD 129.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. ARM Architectures: http://www.arm.products/processors/instruction-set-architectures, ARM Information Center, 2016

  2. ARM Cortex A9 MPcore: “Cortex A9 MPcore Technical Reference Manual”, ARM Information Center, 2016.

    Google Scholar 

  3. ARM Cortex-8: “ARM Cortex-A8 Technical Reference Manual”, ARM Information Center, 2010

    Google Scholar 

  4. ARM926EJ-ST: “ARM926EJ-S Technical Reference Manual”, ARM Information Center, 2008

    Google Scholar 

  5. ARM926EJ-SV: “Versatile Application Baseboard for ARM926EJ-S User guide”, ARM Information Center, 2010

    Google Scholar 

  6. ARM PL011: “PrimeCell UART (PL011) Technical Reference Manual”, ARM Information Center, 2016.

    Google Scholar 

  7. ARM PrimeCell Color LCD Controller PL110: “ARM Versatile Application Baseboard for ARM926EF-S”, ARM Information Center, 2016

    Google Scholar 

  8. ARM Programming: “ARM Assembly Language Programming”, http://www.peter-cockerell.net/aalp/html/frames.html

  9. ARM toolchain: http://gnutoolchains.com/arm-eabi, 2016

  10. QEMU Emulators: “QEMU Emulator User Documentation”, http://wiki.qemu.org/download/qemu-doc.htm, 2010.

Download references

Author information

Authors and Affiliations

Authors

Appendices

List of Sample Programs

  • C2.1: ARM assembly programming

  • C2.2: Sum of integer array in assembly

  • C2.3: Call assembly function from C

  • C2.4: Call C function from assembly

  • C2.5: UART driver

  • C2.6: LCD driver for displaying images

  • C2.7: LCD driver for displaying text

Problems

  1. 1.

    The example program C2.2 contains three highlighted instructions:

    sub r2, r2, #1 // r2-- cmp r2, #0 // if (r2 != 0) bne loop // goto loop;

    1. (1).

      If you delete the cmp instruction, the program would not work. Explain why.

    2. (2).

      However, replacing the three lines with:

      subs r2, r2, #1 bne loop

  • would work. Explain why.

  1. 2.

    In the assembly code of the program C2.4, a, b, and c are adjacent. Modify the assembly code by letting R2 point at the first word a. Then:

    1. (1).

      Access a, b, and c by using R2 as a base register with offsets.

    2. (2).

      Access a, b, and c by using R2 as a base register with post-indexed addressing.

  2. 3.

    In the example program C2.4, instead of defining a, b, and c in the assembly code, define them as initialized globals in the t.c file:

    int a = 1, b = 2, c = 0;

  • Declare them as global symbols in the ts.s file. Compile and run the program again.

  1. 4.

    GPIO programming: Assume that BASE is the base address of a GPIO, and the GPIO registers are at the offset addresses IODIR, IOSET, IOCLR, and IOPIN. The following shows how to define them as constants in ARM assembly code and C:

    .set BASE, 0x101E4000 // #define BASE 0x101E4000 .set IODIR, 0x000 // #define IODIR 0x000 .set IOSET, 0x004 // #define IOSET 0x004 .set IOCLR, 0x008 // #define IOCLR 0x008 .set IOPIN, 0x00C // #define IOPIN 0x00C

  • Write a GPIO control program in both assembly and C to perform the following tasks:

    1. (1).

      Program the GPIO pins as specified in Sect. 2.8.1.

    2. (2).

      Determine the state of the GPIO pins.

    3. (3).

      Modify the control program to make the LED blink while the input switch is closed.

  1. 5.

    The example program C2.6 assumes that every image size is h <= 640 and width <= 480 pixels. Modify the program to handle BMP images of larger sizes by:

    1. (1).

      Cropping: Display at most 480 × 640 pixels.

    2. (2).

      Shrinking: Reduce the image size by a factor, e.g., 2, but keep the same 4:3 aspect ratio.

  2. 6.

    Modify the example program C2.6 to display a sequence of slightly different images to do animation.

  3. 7.

    Many image files, e.g., JPG images, are compressed, which must be uncompressed first. Modify the example program C2.6 to display (compressed) images of different format, e.g., JPG image files.

  4. 8.

    In the LCD display driver program C2.7, define tab_size = 8. Each tab key (\t) expands to eight spaces. Modify the LCD driver to support tab keys. Test the modified LCD driver by including \t in printf() calls.

  5. 9.

    In the LCD driver of program C2.7, scroll-up of one line is implemented by simply copying the entire frame buffer. Devise a more efficient way to implement the scroll operation. HINT: The display memory may be regarded as a circular buffer. To scroll up one line, simply increment the frame buffer pointer by line size.

  6. 10.

    Modify the example program C2.7 to display text with different fonts.

  7. 11.

    Modify the example program C2.8 to implement long jump by using the code of Sect. 2.7.3.3. Use UART0 to get user inputs but display outputs to the LCD. Verify that long jump works.

  8. 12.

    In the LCD driver, the generic printf() function is defined as:

    int printf(char *fmt, …); // note the 3 dots

  • In the implementation of printf(), it assumes that all the parameters are adjacent on stack, so that they can be accessed linearly. This seems to be inconsistent with the calling convention of ARM C, which passes the first four parameters in r0–r3 and extra parameters, if any, on stack. Compile the printf() function code to generate an assembly code file. Examine the assembly code to verify that the parameters are indeed adjacent on stack.

Rights and permissions

Reprints and permissions

Copyright information

© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Wang, K.C. (2023). ARM Architecture and Programming. In: Embedded and Real-Time Operating Systems. Springer, Cham. https://doi.org/10.1007/978-3-031-28701-5_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-28701-5_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-28700-8

  • Online ISBN: 978-3-031-28701-5

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics