5.44 · exercise
Mirror, mirror
The starter reads a count n (0 to 16) and then n numbers into the word array list in .bss, and prints the array at the end. Reverse the array in place before it is printed, so the last number comes out first.
In place means inside list itself, with no second array. Point one register at the first element and another at the last, swap the two words they point at, then move both pointers one element toward the middle. Stop when they meet or cross. Post-index addressing, such as [left_r], 4, uses the address in the register and then adds 4 to it, so one instruction can both store and step.
What is checked
- the line
mirrored:followed by the numbers in reverse order - the program exits cleanly
- the array is changed in memory (
strpresent) - your program also runs on lists you do not see: odd and even lengths, negative numbers, a single number, and an empty list
specification
stdin8
3 1 4 1 5 9 2 6
stdoutprints the right output
exitexits with the right code
sourceuses
strhiddenright 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.