5.32 · exercise

the leaky frame

warning

This program is broken. Find the bug and fix it so the checks pass.

This program stashes a lucky number in its stack frame and prints it back. It should be a two-line story. Run it: the program dies before printing anything, exactly the way it would crash with a bus error on the course servers.

The rule it breaks: sp must stay 16-byte aligned at every moment a call happens. Count the bytes this frame allocates and check them against the course's alignment formula, alloc = -(16 + locals) & -16. Fix the allocation (and its matching deallocation) so the frame is legal.

what is checked

  • the lucky number is printed
  • the program exits cleanly
  • the value still makes its round trip through the frame (str and ldr intact)

Specification

args
stdoutprints the expected output
exitexits with the expected code
sourceuses str
sourceuses ldr

Checked by running your program against expected behavior, never by matching a stored solution.

loading editor...
Open in playground