C8 Computer organization · Practice
The stack and function calls
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
sp holds 0xADF0. A chain of 1 nested calls each makes a 16-byte frame. What does sp hold at the deepest point?
Check
Finish triple, a function that returns 3 × its argument. The main program passes n in a0 and calls it.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Finish nine, which returns 9 × its argument by calling triple twice. The stack must be back where it started when the program stops.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
A recursive function makes a 32-byte frame on each call, and the stack has 1 KiB (1 KiB = 1024 bytes). How many calls deep can it go before the stack runs out?
Check
A function uses 2 saved registers and makes calls if c = 1 (here c = 0).
(a)
How many registers must it save on the stack?
(b)
How big is its frame, keeping sp a multiple of 16?
Check
sp = 0xADF0. After 1 16-byte frames, sp?
Check
512 bytes of stack, 32-byte frames. Maximum depth?
Check
Finish add3, which returns the sum of its three arguments.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C8