A simple computer
has been designed to have the following general
registers that are each 16-bits wide: AX, BX, CX, and
computer has the following simple operations that it can
perform on any of the registers:
reg2 - moves value of reg2 into reg1.
<value> - moves numeric value specified into
reg2 - adds value of reg2 to reg1 and
stores the sum in reg1.
<value> - adds the numeric value specified to
reg1 and stores this sum in reg1.
reg1 - subtracts the value in reg2 from
the reg1 and stores this in reg1.
<value> - subtracts the numeric value
specified from reg1 and stores this in reg1.
reg1 - displays value in reg1 (in
decimal) followed by a CR/LF.
- signifies the end of the program.
Note: regx can
be any of the registers (AX, BX, CX, or DX) and <value>
is any whole decimal number 0 – 65535. Assume that only
a comma separates the destination and source fields.
Your task is to
write a code interpreter that will execute a given
program to completion.
Your program will
be given an input file (prob14.in) with one operation
per line. It should execute all instructions until it
reaches a “HLT”, and then exit. A sample input file is
Write the output
to prob14.out as follows: