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).
BeagleBone Black ARM CPU Specification
Raspberry Pi ARM CPU Specification
Raspberry Pi Broadcom Board Specification
Direct-connect the Pi to your laptop
$ docker run dmhansen/armv7-debian-devThis 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-registerYou should now be able to run the original ARM docker image and obtain an interactive shell session with:
$ docker run --platform linux/arm -it dmhansen/armv7-debian-devwhich 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 --platform linux/arm -it -v /Users/dhansen/arm:/root/arm dmhansen/armv7-debian-devshares 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.
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:
.s
suffix (e.g., foo.s
)
gcc
:
$ gcc -o foo foo.sAlternatively, 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.oNote 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
.
ARM Assembly Quick Reference - we'll use a relatively small subset of these instructions.
Last modified: , by David M. Hansen