A simple bytecode interpreter, inspired by the the Advent of Code
Integer codes implemented so far:
1
(arg0 arg1 arg2
): sums the values referred to byarg0
andarg1
and writes it to the location referred to byarg2
2
(arg0 arg1 arg2
): multiplies the values referred to byarg0
andarg1
and writes it to the location referred to byarg2
3
(arg0
): reads a value from the input tape and stores it in the location referred to byargs0
4
(arg0
): writes to the output tape the value referred to byargs0
5
(arg0 arg1
): ifarg0
is not zero, jumps toarg1
6
(arg0 arg1
): ifarg0
is zero, jumps toarg1
7
(arg0 arg1 arg2
): writes1
to the location referred to byarg2
ifarg0
is less thanarg1
,0
otherwise8
(arg0 arg1 arg2
): writes1
to the location referred to byarg2
ifarg0
is equal toarg1
,0
otherwise99
: terminate execution
Integer codes are assumed to have 5 digits. The last two digits identifies the operation as described as above. The first, second and third digits determine the mode of the first second and third arguments:
0
: read the value from the location given by the argument1
: immediate mode, the argument is the value to be used in the operation If an argument refers to a store location (eg, the third argument for code1
, or the first one for code5
), the argument cannot be in imediate mode.