Source: Duet
Part 1: Create a virtual machine with the following instruction set:
snd X
plays a sound with a frequency equal to the value ofX
set X Y
sets registerX
toY
add X Y
set registerX
toX + Y
mul X Y
sets registerX
toX * Y
mod X Y
sets registerX
toX mod Y
rcv X
recovers the frequency of the last sound played, ifX
is not zerojgz X Y
jumps with an offset of the value ofY
, iffX
is greater than zero
In most cases,
X
andY
can be either an integer value or a register.
What is the value recovered by
rcv
the first timeX
is non-zero?