Lectures‎ > ‎

Week04

ARMv7 Assembly on Raspbian

A good introduction:

Another good tutorial:

ARM Reference Material

ARMv7 Instruction Set (PDF)


First ARM Assembly Program

/* -- first.s */
/* This is a comment */
.global main /* 'main' is our entry point and must be global */
.func main   /* 'main' is a function */
 
main:          /* This is main */
    mov r0, #2 /* Put a 2 inside the register r0 */
    bx lr      /* Return from main */

To assemble and run on a Raspberry Pi:

$ as -o first.o first.s
$ gcc -o first first.o
$ ./first
$ echo $?
2

Alternatively:

$ gcc -o first first.s
$ ./first
$ echo $?

The gcc compiler knows how to call the assembler and link the code to create an executable.

Using GDB to Single Step Machine Code

Comments