opcodes - HenryLoenwind/4bit GitHub Wiki
All Opcodes have exactly one 4-bit parameter. Depending on the opcode that parameter either is a verbatim value (notation: NXT) or a register (notation R__).
- NXT: The direct parameter of the opcode as a verbatim value.
- R__: The direct parameter of the opcode as a register reference.
- A ° B: An operation involving A and B.
- A => B: A is read and B is written to by this opcode.
- A, B: List of A and B
- A+B: A and B are added to each other.
There are 16 opcodes:
Ends the program execution and returns NXT. This operation is final, the program cannot be resumed. All registers and the data memory are lost.
Adds ACC and the parameter register, stores the result in ACC. Sets the STS bits according to the result.
Subtracts the parameter register from ACC and stores the result in ACC. Sets the STS bits according to the result.
Multiplies ACC and the parameter register, stores the result in ACC. Sets the STS bits according to the result.
Divides ACC by the parameter register, stores the result in ACC. Sets the STS bits according to the result.
Computes a bitwise AND between ACC and the parameter register, stores the result in ACC. Sets the STS bits according to the result.
Computes a bitwise OR between ACC and the parameter register, stores the result in ACC. Sets the STS bits according to the result.
Computes a bitwise XOR between ACC and the parameter register, stores the result in ACC. Sets the STS bits according to the result.
Compares ACC and the parameter register, stores the result in ACC. Sets the STS bits accordingly. (Note: The ZERO bit is set according to the ACC value, independent of the parameter register.)
Loads NXT into the LOS register (LOS==ACC by default). Sets the STS bits according to the loaded value.
(ldn = LoaD Nxt)
Loads the value from the address ADR+NXT in the data memory into the LOS register (LOS==ACC by default). Sets the STS bits according to the loaded value.
(ldm = LoaD Memory)
Stores the value of the LOS register (LOS==ACC by default) into the address ADR+NXT in the data memory.
(sto = STOre)
Copies the value of the parameter register into ACC. Sets the STS bits according to the copied value.
(mvr = MoVe Register)
Copies the value of ACC into the parameter register. Sets the STS bits according to the copied value.
(mva = MoVe Acc)
Executes a bitwise AND between NXT and STS. If the result is not zero, sets the instruction pointer to ADR.
Note: "jmp 0" is a NOP. "zro STS; jmp 15" is an unconditional jump.
Sets the parameter register to 0. Sets the STS bits according to the new value.