; initialize SP to lower address so that ; it can be viewed in "Memory Contents" MOV SP, #0x1100 MOV R0, #7 ; a=7 MOV R1, #9 ; b=9 SUB SP, SP, #8 ; get 2 cells (8 bytes) for params STR R0, [SP, #4] ; send a, put it in "first" spot STR R1, [SP, #0] ; send b, put it in "second" spot BL SUM_A_B ; call the function LDR R2, [SP, #0] ; copy result from top of stack ADD SP, SP, #12 ; release 3 cells (2 params + 1 result) END ; stop overall execution SUM_A_B SUB SP, SP, #4 ; get 1 cell (4 bytes) for result STMDB SP!, {LR, R11, R0, R1, R2} ; preserve 5 registers: ; - must use ! to change SP ; - careful with DB vs IA (Dec Before, Inc After) ADD R11, SP, #28 ; skip 7 cells to get to beginning of frame LDR R0, [R11, #0] ; copy a from params via FP LDR R1, [R11, #-4] ; copy b from params via FP ADD R2, R0, R1 ; a+b STR R2, [R11, #-8] ; put result in its cell via FP LDMIA SP!, {LR, R11, R0, R1, R2} ; restore the registers ; - must use ! to change SP ; - DB become IA (opposite dir) MOV PC, LR ; leave by setting program counter to return address