The Register Machine
You are to simulate a simple machine with 8 registers and a program consisting of assembly-like instructions. Each register initially holds 0 and can store a 64-bit unsigned integer.
The machine executes instructions sequentially. Execute the program and output all values printed by PRINT commands.
Instructions
The machine supports the following instructions:
LOAD reg val: Set registerregto valuevalADD reg1 reg2: Add the value in registerreg2to registerreg1(reg1 += reg2)SUB reg1 reg2: Subtract the value in registerreg2from registerreg1(reg1 -= reg2)AND reg1 reg2: Bitwise AND registersreg1andreg2, store inreg1(reg1 &= reg2)OR reg1 reg2: Bitwise OR registersreg1andreg2, store inreg1(reg1 |= reg2)XOR reg1 reg2: Bitwise XOR registersreg1andreg2, store inreg1(reg1 ^= reg2)SHL reg k: Shift the value in registerregleft bykbits (reg <<= k)SHR reg k: Shift the value in registerregright bykbits (reg >>= k)PRINT reg: Output the decimal value of registerregon a new lineHALT: Stop execution
All arithmetic operations use 64-bit unsigned integers with standard wraparound on overflow. Shift operations with k >= 64 result in 0.
Input
The first line contains n (1 ≤ n ≤ 1000), the number of instructions.
The next n lines each contain one instruction in the format described above. Register indices are in the range [0, 7]. Values val and k are non-negative integers up to 10^18.
Output
Print each value from PRINT commands in the order they are executed, one per line.
Notes
- The program is guaranteed to contain at least one
HALTinstruction and will halt before running more thanninstructions. - All register indices in instructions refer to registers 0 through 7.