The secret handshake
Two friends send each other a secret handshake as a number. Only the low five bits count:
- bit 0 (1): wave
- bit 1 (2): nod
- bit 2 (4): wink
- bit 3 (8): clap
- bit 4 (16): do the actions in reverse order
The starter reads the number into code_r and holds the five strings. Print the action for each set bit among bits 0 to 3, one per line, lowest bit first. When bit 4 is set, print them highest bit first instead. Bits above bit 4 mean nothing. When none of bits 0 to 3 is set, print no handshake.
tst works out the AND of two values and sets the flags from it without keeping the result, so tst code_r, 4 then b.ne jumps when bit 2 is set. A mask (a value with only the bits you care about set) that walks through 1, 2, 4, 8, or 8, 4, 2, 1, lets one loop test every bit.
With the sample input 11 (binary 01011) the output is:
wave
nod
clap
What is checked
- the actions for the sample input, one per line
- the program exits cleanly
- the bits are tested with
tst - the same program gives the right handshake for other numbers, including 0, reversed codes, and a negative number
specification
tstWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.