At the time of writing, I work for an AV company. I saw that they only had expertise in X86 assembly language, and yet most people I knew accessed the internet from ARM-based telephones and tablets. I had a philosophical preference for RISC architectures, so decided to be proactive and learn more about these ARM chips.
Both of my computers run Debian GNU/Linux.
Here I use the GNU assembler, gas, the GNU C compiler, gcc, the GNU linker, ld and the GNU debugger, gdb.
I can recommend Thinkingeek.com as a good source of tutorials for ARM assembly programming.
For the first examples, I followed those supplied with the excellent X86 assembly language book,Professional Assembly Language by Richard Blum.
The code is at email@example.com:bobblestiltskin/professional_assembly_language.git if you want to play with it.
Familiarity with gdb is useful. e.g.
- Use b _start to set a break point at the label _start:
- Use run to run to the break point.
- s to step through from the break point
- inspect registers or abbreviate to i r
- x/4d &data to eXamine 4 decimal items of data
This page explains the basic usage well of gdb.
Communicating with Linux
We can invoke a system call to the operating system, exit, which allows us to pass back one parameter, as the exit code of the program.
.global _start _start: mov r0, #42 @ the value in r0 is returned as the exit status of the process mov r7, #1 @ set r7 to 1 - the syscall for exit @ calls listed in /usr/include/asm/unistd.h swi 0 @ then invoke the syscall from linux
bob@poland:~/src/asm$ /usr/bin/as -gstabs -o syscall.o syscall.s bob@poland:~/src/asm$ /usr/bin/ld -o syscall syscall.o bob@poland:~/src/asm$ ./syscall bob@poland:~/src/asm$ echo $? 42 bob@poland:~/src/asm$