Lectures‎ > ‎


ARM and CPU basics


ARMv4/v7 Details

16 general purpose registers with an addition flags register
General purpose: r0..r15
Flags: cpsr (Current Program Status Register)
Memory is byte addressable, but read/write words with ldr and str must be give word aligned addresses
Some registers have special usage or special conventions
r15 is the pc (program counter)
r14 is the lr (link register)
r13 is the sp (stack pointer)
The other registers can be used for computation, but they have restrictions when implementing function calls (more below).

ARM Instructions

data processing: add, sub, mul, ror, etc.
control: b, beq, bl, bx
memory: ldr, str, ldrb, strb

ARM Assembly DDCA Book vs RPi as (gas)

GAS stands for GNU Assembler
Note that the book uses a slight different syntax than what we will be using to write and run assembly code on the Raspberry Pi.
Here are the differences:
    DDCA: uppercase for labels and instructions, GAS: lowercase for labels and instructions
    DDCA: no colon after labels, GAS: you must use a colon after a label
    DDCA: use mov pc, lr to return from a function, GAS: use bx lr to return from a function
    DDCA: no directives, GAS: need some directives like .global to expose labels to other code
    DDCA: comments semicolon ;, GAS: C/C++ style comments /* */ or //

ARM Conditional Execution 

if statements
for/while loops

ARM Memory

Static vs dynamic.
We will use static and stack allocated memory.

The ARM Stack

The Stack is just a region of memory that is used to for temporary memory allocation.
It is used to support function calls.
The stack can be used to preserve register values, pass more than 4 arguments, and for local variable allocation.
The stack pointer (SP) holds the address of the current location on the stack.
Stacks typically grow down (that is the SP starts at a high address).
To allocate stack memory, subtract from SP.
Functions must restore SP before returns (this will deallocated the stack memory).
Provide a picture.
Show some code.