Got the start of encoding opcodes.

This commit is contained in:
2022-08-26 18:27:41 +00:00
parent 0d060248cb
commit eb5e2c506e
5 changed files with 66 additions and 19 deletions
+29 -8
View File
@@ -16,6 +16,33 @@ Instruction instructions[OPCODECOUNT] = {
{ "nop", NOP, None, None}
};
unsigned char GetInstructionMask(TokenType type, TokenClass parameterOneType) {
switch (type) {
case COPY:
if (parameterOneType == Reg) return 0x20; //0b00100000;
return 0xA0;////0b10100000;
case ADD:
return 0x40;//0b01000000;
case SUB:
return 0x60;//0b01100000;
case CMP:
return 0x80;//0b10000000;
case JZ:
return 0x01;//0b00000001;
case INT:
return 0x02; //0b00000010;
case JMP:
return 0x06;//0b00000110;
case IN:
return 0x07;//0b00000111;
case OUT:
return 0x08;//0b00001000;
default:
return 0x00;
}
}
/*
NOP - 0000 0000 NOP
JZ - 0000 0001 JZ Address
@@ -24,14 +51,14 @@ Instruction instructions[OPCODECOUNT] = {
RET - 0000 0100 RET
CALL - 0000 0101 CALL Address
JMP - 0000 0110 JMP Address
IN - 0000 0111 IN Constant
OUT - 0000 1000 OUT Constant
COPY - 0010 0XXX COPY REG, REG
- 0010 1XXX COPY REG, Constant
- 0011 0XXX COPY REG, Address
- 1010 0XXX COPY Address, REG
- 1010 1XXX COPY Address, Constant
- 1011 0XXX COPY Address, Address
ADD - 0100 0XXX ADD REG, REG
- 0100 1XXX ADD REG, Constant
SUB - 0110 0XXX SUB REG, REG
@@ -39,17 +66,11 @@ Instruction instructions[OPCODECOUNT] = {
CMP - 1000 0XXX CMP REG, REG
- 1000 1XXX CMP REG, Constant
- 1001 0XXX CMP REG, Address
//Read from port specified by either a register or a constant
IN - 1100 0XXX IN REG
- 1101 0XXX IN Constant
OUT - 1111 1XXX OUT REG
*/
//COPY X01X XXXX
//ADD 010X XXXX
//SUB 011X XXXX
//CMP 100X XXXX
//IN 110X XXXX
//REG XXX0 0XXX
//Constant XXX0 1XXX
//Address XXX1 0XXX