Return to sender
A struct bigger than 16 bytes does not fit in x0 and x1, so it comes back another way. The caller, the code making the call, reserves room for the struct in its own frame and passes that address in x8. The callee, the subroutine being called, writes the struct there. The caller picks the address and the callee delivers to it.
Write describe(n), which fills in this struct for the n in x0:
struct profile {
long square; // n * n
int sign; // -1, 0 or 1
int odd; // 1 if n is odd, else 0
int last; // the last decimal digit of n, never negative
};
Work out each field's offset first. A long starts at a multiple of 8, and the whole struct is padded out to a multiple of 8 as well, so its 20 bytes of fields take 24. Store each field at its own width: an x register for the long, a w register for each int.
Then finish main: grow its frame to hold the struct, point x8 at it, call describe, and load the fields into x2, w3, w4 and w5 for the printf that is already there. The starter's input prints:
7: square 49, sign 1, odd 1, last digit 7
-12: square 144, sign -1, odd 0, last digit 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 0, negative numbers, a square too big for 32 bits, and no input at all
- the struct travels through memory: the source uses
x8andstr
specification
x8strWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.