Lecture 4-5 - ARM - Assembly - 3 (New)
Lecture 4-5 - ARM - Assembly - 3 (New)
CF Destination 0 Destination CF
Destination CF
Immediate value
8 bit number, with a range of 0-
ALU 255.
Rotated right through even
number of positions
Allows increased range of 32-bit
Result constants to be loaded directly
into registers
Branch Instructions
31 28 27 25 24 23 0
Cond 1 0 1 L Offset
BL <subroutine>
Stores return address in LR
Returning implemented by restoring the PC from LR
For non-leaf subroutines, LR will have to be stacked
func1 func2
STMFD :
: sp!,{regs,lr}
:
: :
:
BL func1 BL func2
:
: :
:
: LDMFD
sp!,{regs,pc} MOV pc, lr
Base-update possible: r0 r1
LDM r10!,{r0-r6} r0
LDM/STM for Stack Operations
Traditionally, a stack grows down in memory, with the last
“pushed” value at the lowest address. The ARM also supports
ascending stacks, where the stack structure grows up through
memory.
The value of the stack pointer can either:
• Point to the last occupied address (Full stack)
– and so needs pre-decrementing/incrementing (ie before the push)
• Point to an unoccupied address (Empty stack)
– and so needs post-decrementing/incrementing (ie after the push)
The stack type to be used is given by the postfix to the
instruction:
• STMFD / LDMFD : Full Descending stack
• STMFA / LDMFA : Full Ascending stack.
• STMED / LDMED : Empty Descending stack
• STMEA / LDMEA : Empty Ascending stack
Note: ARM Compilers will always use a Full descending stack.
Stack Examples
STMFD sp!, STMED sp!, STMFA sp!, STMEA sp!,
{r0,r1,r3-r5} {r0,r1,r3-r5} {r0,r1,r3-r5} {r0,r1,r3-r5}
0x418
SP r5 SP
r4 r5
r3 r4
r1 r3
r0 r1
Old SP Old SP r5 Old SP Old SP r0 0x400
r5 r4
r4 r3
r3 r1
r1 r0
SP r0 SP
0x3e8