Change for a twenty
A customer pays with a twenty-dollar bill, 2000 cents. The starter reads the price in cents, from 0 to 2000. Work out the change, then split it into as few coins as possible: as many quarters (25 cents) as fit, then dimes (10), then nickels (5), then pennies (1). Leave the results in change_r, quarters_r, dimes_r, nickels_r and pennies_r; the starter prints them.
AArch64 has no remainder instruction. sdiv gives how many whole times one number fits in another, and msub multiplies two registers and subtracts the product from a third, which is exactly the leftover:
sdiv w9, w12, w10 // w9 = w12 / w10, fraction dropped
msub w13, w9, w10, w12 // w13 = w12 - w9 * w10, the remainder
For a price of 1541 the change is 459 cents: 18 quarters make 450, which leaves 9 cents, and 9 cents is 0 dimes, 1 nickel and 4 pennies.
What is checked
- with input
1541the output ischange in cents: 459, then25c x 18,10c x 0,5c x 1and1c x 4, one per line - the program exits cleanly
- the leftovers come from
msub - the program also runs on prices you do not see, including one that needs no change at all and one that needs every kind of coin
specification
msubWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.