Two answers, one call
A function hands back one value in x0, but a division has two answers. divmod(a, b, &q, &r) gets both out: the caller (the code making the call) passes the addresses of two of its own variables, and divmod writes the quotient and the remainder into them. It returns 0 in w0 when it worked, and -1 when b is 0, in which case it writes nothing.
The starter's main reads pairs of numbers into its frame until the input runs out, and prints each result from the frame slots q_s and r_s. Write divmod, and fill in the call in main: a in x0, b in x1, and the addresses of the two slots in x2 and x3 (add x2, fp, q_s puts an address in a register).
Use sdiv, which rounds toward zero the way C does, so -17 / 5 is -3 remainder -2. The remainder is a - q * b, one msub. Check b first: dividing by zero does not stop an ARMv8 program, sdiv quietly answers 0.
main exits with the number of pairs that had no answer, so a script running the program can tell something went wrong.
The starter's input prints:
17 / 5 = 3 remainder 2
100 / 7 = 14 remainder 2
What is checked
- the two lines above
- the program exits with status 0
- the same checks on other inputs the checker keeps hidden, including negative numbers, a divisor of 0 (the exit status must count them), and no input at all
sdivdoes the division andstrwrites the answers
specification
sdivstrWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.