0
0
ARM Architectureknowledge~10 mins

Stack frame setup in ARM Architecture - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to push the link register onto the stack at the start of a function.

ARM Architecture
push [1]
Drag options to blanks, or click blank then click option'
A{r0}
B{pc}
C{sp}
D{lr}
Attempts:
3 left
💡 Hint
Common Mistakes
Using {pc} instead of {lr} will push the program counter, which is not typical for function prologue.
Pushing {sp} or {r0} is incorrect for saving return address.
2fill in blank
medium

Complete the code to allocate 16 bytes on the stack for local variables.

ARM Architecture
sub sp, sp, [1]
Drag options to blanks, or click blank then click option'
A#4
B#8
C#16
D#32
Attempts:
3 left
💡 Hint
Common Mistakes
Using #8 only allocates 8 bytes, which may be insufficient.
Using #32 allocates too much space unnecessarily.
3fill in blank
hard

Fix the error in the instruction that restores the stack pointer after a function call.

ARM Architecture
add sp, sp, [1]
Drag options to blanks, or click blank then click option'
A#16
B#12
C#8
D#4
Attempts:
3 left
💡 Hint
Common Mistakes
Adding back #8 or #12 bytes will not fully restore the stack pointer.
Adding #4 bytes is too little and causes stack corruption.
4fill in blank
hard

Fill both blanks to correctly save and restore the frame pointer (r7) in the function prologue and epilogue.

ARM Architecture
push [1]
...
pop [2]
Drag options to blanks, or click blank then click option'
A{r7}
B{lr}
C{r6}
D{sp}
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing {lr} instead of {r7} will save the return address, not the frame pointer.
Using different registers for push and pop causes errors.
5fill in blank
hard

Fill all three blanks to create a stack frame setup that saves lr and r7, allocates 12 bytes, and restores them properly.

ARM Architecture
push [1]
sub sp, sp, [2]
...
add sp, sp, [3]
Drag options to blanks, or click blank then click option'
A{lr, r7}
B#12
D{r7}
Attempts:
3 left
💡 Hint
Common Mistakes
Using {r7} alone in push does not save lr.
Allocating different amounts in sub and add causes stack imbalance.