ARM Nested Procedures
Nested Procedures
int sumSquare(int x, int y){ return (mult(x, x) + y); }
sumSquare: push {r4-r11, lr} MOV r4, r1 MOV r1, r0 BL mult ADD r0, r0, r4 pop {r4-r11, lr} BX lr @ then?
main: MOV r0, #2 MOV r1, #3 BL sumSquare MOV r3, r0
Without pushing lr, calling another function overwrites it.
String constants in ARM
x = 0xaabbccdd; printf("%d\n", x);
// how printf works %int printf(const char *format, ...)
Where to store
- String “%d\n” — in data segment
- Value 0xaabbccdd —
String formats (unfinished)
.ascii
.asciz
.data mystr: .asciz "%d\n" mynum: .word 0xaabbccdd print_fun: push {lr} LDR r0, =mystr @ location with label mystr is store in r0 LDR r1, =mynum LDR r1, [r1] BL printf pop {lr} BX lr
Alignment
.text .align 2
mystr is placed in a location that is a multiple of 2^2 = 4.
Data objects should start at memory addresses that are divisible by the size of the data object
- short (2-byte) at address divisible by 2
- int (4-bytes) at address divisible by 4
- double (8-byte) at address divisible by 8
struct p { char x; int y; }; struct p sp;
In this case, sizeof(p) is 8. int should be aligned.
Published on November 2, 2015