Loop: LSL X10,X22,#3 ADD X10,X10,X25 LDUR X9,[X10,#0] SUB X11,X9,X24 CBNZ X11,Exit ADDI X22,X22,#1 B Loop Exit: ...
Basic Blocks
A sequence of instructions with
No embedded branches (except at end)
No branch targets (except at beginning)
Means either the entire block or none is executed
Compilers and processors do optimizations on basic blocks
Program Pointers
Program Counter (PC)
Points to current instruction being run
In intervals of 4 because each instruction is 4 bytes
Frame Pointer
Points to base address of function’s frame
Allows you to easily move stack pointer back to where it was before a procedure was called
Stack Pointer
Points to top of stack
Grows from the top down in most systems
→ pushing subtracts 4 from the address
Program Memory Layout
Structure
Stack 🔽 (Stack pointer to here)
(Space)
Dynamic Data 🔼
Static Data
Text (Program counter to here)
Reserved
Bookkeeping operations by OS
That’s actually an abstraction because the OS could give us non contiguous memory and then tell us that it’s contiguous
OSs do defragmentation to reduce that because contiguous memory is much faster
Stack
Stack pointer must be manually moved in assembly
SUBI SP,SP,#24 // move the stack pointer up 24 STUR X10,[SP,#16] // store at botom of stackSTUR X9,[SP,#8] // store at middle of stackSTUR X19,[SP,#0] // store at top of stackADD X9,X0,X1ADD X10,X2,X3SUB X19,X9,X10ADD X0,X19,XZRLDUR X10,[SP,#16] // get from bottom of stackLDUR X9,[SP,#8] // get from middle of stackLDUR X19,[SP,#0] // get from top of stackADDI SP,SP,#24 // move the stack pointer down 24BR LR