5.45 · exercise
Three in a row
Read three integers, keep each one in its own local variable in the stack frame, and print them smallest first on one line.
The starter sets up a frame with room for three 4-byte locals at the offsets a_s, b_s and c_s. scanf needs the address of the place where it should store a number; for a frame local that address is fp plus the local's offset, built with add x1, fp, a_s. Once the three values are loaded into a_r, b_r and c_r, compare pairs and swap any pair that is out of order until a_r <= b_r <= c_r. Try your steps on an input where the smallest number comes last.
What is checked
- the three numbers in ascending order, separated by single spaces
- the program exits cleanly
- the numbers are read into the frame (
addpresent) and compared (cmppresent) - your program also runs on inputs you do not see: every order, negative numbers, repeated numbers, and the largest and smallest 32-bit values
specification
stdin42 7 19
stdoutprints the right output
exitexits with the right code
sourceuses
addsourceuses
cmphiddenright output and exit code on 6 more inputs you do not see
We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.