Halfword by halfword
A locker's 64-bit code is 0xbeefcafef00dffff. Build it in code_r; the starter then adds a number n read from input and prints the code, n, and the sum.
One mov can only place a 16-bit piece of a number, a halfword, into a register. movz writes one halfword and clears every other bit. movk writes one halfword and keeps the other bits as they were (the k is for keep). Add lsl 16, lsl 32 or lsl 48 to pick which halfword. The code splits into four:
| bits | halfword |
|---|---|
| 63 to 48 | 0xbeef |
| 47 to 32 | 0xcafe |
| 31 to 16 | 0xf00d |
| 15 to 0 | 0xffff |
Start with one movz, then add three movk. Try an input of 1: the low halfword rolls over from 0xffff to 0x0000 and carries into the next one, because the four pieces are one number.
What is checked
- with input
0the line reads0xbeefcafef00dffff + 0 = 0xbeefcafef00dffff - the program exits cleanly
- the code is built with
movzandmovk, not written as one number - the program also runs on inputs you do not see, so it has to work for any input, not only this one
specification
movzmovkcafef00dCAFEF00DWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.