5.17 · exercise
reverse the digits
Take 9317 and print 7139: the same digits, reversed, as a number.
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)
Specification
args
stdoutprints the expected output
exitexits with the expected code
sourceuses
msubsourcecomputes the result (does not hardcode it)
Checked by running your program against expected behavior, never by matching a stored solution.
loading editor...