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 byarg0andarg1and writes it to the location referred to byarg22(arg0 arg1 arg2): multiplies the values referred to byarg0andarg1and writes it to the location referred to byarg23(arg0): reads a value from the input tape and stores it in the location referred to byargs04(arg0): writes to the output tape the value referred to byargs05(arg0 arg1): ifarg0is not zero, jumps toarg16(arg0 arg1): ifarg0is zero, jumps toarg17(arg0 arg1 arg2): writes1to the location referred to byarg2ifarg0is less thanarg1,0otherwise8(arg0 arg1 arg2): writes1to the location referred to byarg2ifarg0is equal toarg1,0otherwise99: 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.