5.23 · exercise

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

stdin11
stdoutprints the right output
exitexits with the right code
sourceuses tst
hiddenright output and exit code on 6 more inputs you do not see

We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.

loading editor...

regfile

N clearZ clearC clearV clear

x0–x30 are the integer registers.

X0arg00x0000000000000000
X1arg10x0000000000000000
X2arg20x0000000000000000
X3arg30x0000000000000000
X4arg40x0000000000000000
X5arg50x0000000000000000
X6arg60x0000000000000000
X7arg70x0000000000000000
X8ind0x0000000000000000
X90x0000000000000000
X100x0000000000000000
X110x0000000000000000
X120x0000000000000000
X130x0000000000000000
X140x0000000000000000
X150x0000000000000000
X16ip00x0000000000000000
X17ip10x0000000000000000
X18pr0x0000000000000000
X190x0000000000000000
X200x0000000000000000
X210x0000000000000000
X220x0000000000000000
X230x0000000000000000
X240x0000000000000000
X250x0000000000000000
X260x0000000000000000
X270x0000000000000000
X280x0000000000000000
X29fp0x0000000000000000
X30lr0x0000000000000000
SP0x0000000080000000
PC0x0000000000400000
console

Output prints here as your program runs.

Press step or run under the editor, or feed stdin from the box below.

not assembled

Open in playground