5.21 · exercise
Reverse the digits
Read a number and print it with its digits reversed: 9317 prints as 7139.
Each trip around the loop, peel off the last digit (the remainder mod 10), append it to the running result with result = result * 10 + digit, and cut the source number down by a factor of ten. msub gives you the remainder; madd does the multiply-and-add in one instruction.
What is checked
- the reversed number is printed on its own line
- the program exits cleanly
- the digits are peeled in a loop (
msubpresent, answer not written in) - the same holds for other numbers you do not see: 0, one digit, and trailing zeros (
1200reverses to21)
specification
stdin9317
stdoutprints the right output
exitexits with the right code
sourceuses
msubsourcedoes not hardcode the answer
hiddenright output and exit code on 4 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.