Writing and Testing ARM Assembly

A number of courses use ARM assembly. This page provides general information and links related to mechansims for developing and learning ARM assembly.

One mechanism for developing and testing ARM assembly is to use a physical ARM System On a Chip (SoC). A second mechganism is to use a virtual environment like Docker via an emulator such as QEMU running on your own host system (e.g., Windows or Mac laptop).

ARM-based System-On-a-Chip

BeagleBone Black

BeagleBone Black ARM CPU Specification

Raspberry Pi ARM CPU Specification

Raspberry Pi Broadcom Board Specification

Direct-connect the Pi to your laptop

ARM-based Docker Image

To use this mechanism you'll need to install Docker and then obtain and execute an ARM-based Docker image. You'll need to use the command-line (both your host-OS command-line as well as the UNIX command-line of the ARM-based Docker image). Once you've installed Docker you can download and run an ARM-based Docker image I have created with this command:
$ docker run dmhansen/armv7-debian-dev
This will download the image from a public repository on Docker Hub and attempt to start the "machine"; this will probably result in an error as we also need another machine registered to emulate the ARM architecture. So the second step is to download and register the ARM emulator:
$ docker run --rm --privileged hypriot/qemu-register
You should now be able to run the original ARM docker image and obtain an interactive shell session with:
$ docker run -it dmhansen/armv7-debian-dev
which starts the guest Linux machine and logs you in as the root user.

To make code development easier, I suggest you have the Docker image share a folder with your host OS so you can edit files using a text-editor on your host OS and only compile/execute on the guest machine. For example if I have a folder arm in the home directory of my host OS, adding the -v flag:

$ docker run -it -v /Users/dhansen/arm:/root/arm dmhansen/armv7-debian-dev
shares that folder and makes it accessible in the home directory of the root user of the guest machine (i.e. $ cd ~/arm). I can edit files in the folder using my host machine and then compile and execute the code on the guest machine.

ARM Assembly

We will be writing assembly programs for the ARMv7 architecture. The gcc compiler suite includes an architecture-dependent assembler named as for translating assembly code to machine code. "Architecture-dependent" means that gcc installed on an x86-based Mac running OS/X would generate x86 machine code. The easiest path to development then, is to use gcc and as on the ARM-based system-on-a-chip (SoC) or Docker image. Keep in mind that I will be testing your code on actual hardware (i.e., my SoC).

To use the assembler you:

  1. Write a program in assembly code in a file with a .s suffix (e.g., foo.s)
  2. Translate and assemble your code using gcc:
    $ gcc -o foo foo.s
    Alternatively, you can run the "assembler" explicitly using as to translate your program and produce an object file and then use gcc for final assembly into an executable:
    $ as -o foo.o foo.s
    $ gcc -o foo foo.o
    
    Note that without the -o flag the default output file from gcc is named a.out in both examples. While gcc will generate an executable program, as merely generates an "object" file that must subsequently be linked into an executable using gcc.

A great ARM Assembly tutorial - note that this tutorial assumes ARMv6; ARMv7 includes integer division instructions.

ARM Assembly Quick Reference - we'll use a relatively small subset of these instructions.


Last modified: , by David M. Hansen