Added a distinction between constant numbers and what are effectively memory addresses (i.e. strings and labels).

This commit is contained in:
2022-08-25 19:47:16 -05:00
parent 03d5660677
commit 0e53f9798f
5 changed files with 60 additions and 18 deletions
+35 -8
View File
@@ -3,18 +3,45 @@
#include <string.h>
Instruction instructions[OPCODECOUNT] = {
{ "copy", COPY, Reg, Reg | Immediate16 },
{ "add", ADD, Reg, Reg | Immediate16 },
{ "sub", SUB, Reg, Reg | Immediate16 },
{ "jz", JZ, Immediate16, None },
{ "int", INT, Immediate16, None },
{ "copy", COPY, Reg | Address, Reg | Constant | Address },
{ "add", ADD, Reg, Reg | Constant },
{ "sub", SUB, Reg, Reg | Constant },
{ "jz", JZ, Address, None },
{ "int", INT, Constant, None },
{ "yld", YLD, None, None },
{ "ret", RET, None, None },
{ "cmp", CMP, Reg | Immediate16, Reg | Immediate16 },
{ "in", IN, None, None},
{ "out", OUT, None, None}
{ "cmp", CMP, Reg, Reg | Constant },
{ "in", IN, Constant | Reg, None},
{ "out", OUT, None, None},
{ "nop", NOP, None, None}
};
/*
NOP - 0000 0000
JZ - 0000 0001 JZ Address
INT - 0000 0010 INT Constant
YLD - 0000 0011 YLD
RET - 0000 0100 RET
CALL - 0000 0101 CALL Address
//IN reads from a port number specified by either a register or a constant.
IN - 0000 0110 IN Constant
- 0000 0111 IN REG
COPY - 0000 1XXX COPY REG, REG
- 0001 0XXX COPY REG, Constant
- 0010 0XXX COPY REG, Address
- 0010 1XXX COPY Address, REG
- 0011 0XXX COPY Address, Constant
- 0011 1XXX COPY Address, Address
ADD - 0100 0XXX ADD REG, REG
- 0100 1XXX ADD REG, Constant
SUB - 0101 0XXX SUB REG, REG
- 0101 1XXX SUB REG, Constant
CMP - 0110 0XXX CMP REG, REG
- 0110 1XXX CMP REG, Constant
- 0111 0XXX CMP REG, Address
OUT - 0111 1XXX OUT REG
*/
Register registers[REGISTERCOUNT] = {
{ "r1", R1 },
{ "r2", R2 },