Updated the docs to include new jump operands and setup the assembler to handle parsing all the jump instructions.

This commit is contained in:
2023-03-29 22:30:12 -05:00
parent a9a50055a4
commit 288ba9f9cb
5 changed files with 80 additions and 7 deletions
+15 -3
View File
@@ -103,16 +103,28 @@
\OpcodeTable{0x20}{sub}{Register}{Register}\\[6pt] \OpcodeTable{0x20}{sub}{Register}{Register}\\[6pt]
Performs subtraction on a register with a value from another (or the same) register. Performs subtraction on a register with a value from another (or the same) register.
\section{JMP (Jump)} \section{JMP (Jump)}
\OpcodeTable{0x20}{jmp}{Address}{None}\\[6pt] \OpcodeTable{0x20}{jmp}{Register}{None}\\[6pt]
Jumps unconditionally to a memory address. Sets the Program Counter to Address. Jumps unconditionally to a memory address. Sets the Program Counter to Address.
\section{JZ (Jump if Zero)} \section{JZ (Jump if Zero)}
\OpcodeTable{0x20}{jz}{Register}{None}\\[6pt] \OpcodeTable{0x20}{jz}{Register}{None}\\[6pt]
Jumps to a memory address if the status flag is zero. Jumps to a memory address if the status flag is zero.
\section{JG (Jump if Greater Than)} \section{JG (Jump if Greater Than)}
\OpcodeTable{0x70}{jg}{Address}{None}\\[6pt] \OpcodeTable{0x70}{jg}{Register}{None}\\[6pt]
Jump to the Address if the status flag is greater than zero. Jump to the Address if the status flag is greater than zero.
\section{JL (Jump if Less Than)} \section{JL (Jump if Less Than)}
\OpcodeTable{0x00}{jl}{Address}{None}\\[6pt] \OpcodeTable{0x00}{jl}{Register}{None}\\[6pt]
Jumps to the address if the status flag is less than zero.
\section{JMPA (Jump to Address)}
\OpcodeTable{0x20}{jmpa}{Address}{None}\\[6pt]
Jumps unconditionally to a memory address. Sets the Program Counter to Address.
\section{JZA (Jump to Address if Zero)}
\OpcodeTable{0x20}{jza}{Address}{None}\\[6pt]
Jumps to a memory address if the status flag is zero.
\section{JGA (Jump to Address if Greater Than)}
\OpcodeTable{0x70}{jga}{Address}{None}\\[6pt]
Jump to the Address if the status flag is greater than zero.
\section{JLA (Jump to Address if Less Than)}
\OpcodeTable{0x00}{jla}{Address}{None}\\[6pt]
Jumps to the address if the status flag is less than zero. Jumps to the address if the status flag is less than zero.
\section{AND (Logical AND)} \section{AND (Logical AND)}
\OpcodeTable{0x00}{and}{Register}{Register}\\[6pt] \OpcodeTable{0x00}{and}{Register}{Register}\\[6pt]
+2 -1
View File
@@ -13,7 +13,8 @@ typedef enum {
typedef enum { typedef enum {
ADD, SUB, JZ, INT, YLD, RET, ADD, SUB, JZ, INT, YLD, RET,
CMP, CMPI, NOP, JMP, CALL, LODW, LAA, LODWI, JE, INC, DEC, LOADB, CMP, CMPI, NOP, JMP, CALL, LODW, LAA, LODWI, JE, INC, DEC, LOADB,
STOB, STOW, JG, JL, AND, XOR, OR, NOT, SHR, SHL, POP, PUSH, LODB STOB, STOW, JG, JL, AND, XOR, OR, NOT, SHR, SHL, POP, PUSH, LODB,
JMPA, JZA, JLA, JGA
} Mnemonic; } Mnemonic;
typedef enum { typedef enum {
+5 -1
View File
@@ -17,4 +17,8 @@ cmp r1, 5
and r1, r2 and r1, r2
add r4, r7 add r4, r7
inc r1 ;increment r1 inc r1 ;increment r1
xor r1, r1 ;clear self xor r1, r1 ;clear self
pop r3
jmp unknown_symbol
jmp r4
jz unknown_symbol
+6 -2
View File
@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define OPCODECOUNT 30 #define OPCODECOUNT 34
struct _instruction { struct _instruction {
char* Name; char* Name;
@@ -41,7 +41,11 @@ struct _instruction instructions[OPCODECOUNT] = {
{ "nop", NOP, NoParameter, NoParameter }, { "nop", NOP, NoParameter, NoParameter },
{ "pop", POP, RegisterParameter, NoParameter }, { "pop", POP, RegisterParameter, NoParameter },
{ "push", PUSH, RegisterParameter, NoParameter }, { "push", PUSH, RegisterParameter, NoParameter },
{ "lodb", LODB, RegisterParameter, RegisterParameter} { "lodb", LODB, RegisterParameter, RegisterParameter},
{ "jmpa", JMPA, RegisterParameter, NoParameter},
{ "jza", JZA, RegisterParameter, NoParameter},
{ "jla", JLA, RegisterParameter, NoParameter},
{ "jga", JGA, RegisterParameter, NoParameter},
}; };
void ExpectParameters(Mnemonic mnemonic, OpcodeParameter* paramOne, OpcodeParameter* paramTwo) { void ExpectParameters(Mnemonic mnemonic, OpcodeParameter* paramOne, OpcodeParameter* paramTwo) {
+52
View File
@@ -264,6 +264,58 @@ void HandleOpcode(void) {
case POP: case POP:
ExpectRegister(); ExpectRegister();
break; break;
case JMP:
{
Token* arg = PeekToken();
if (arg->Class == IdentifierClass) {
ExpectIdentifier(0, ForwardParser);
opcode->Value.Mnemonic = JMPA;
opcode->Lemexe = "JMPA";
}
else ExpectRegister();
}
break;
case JZ:
{
Token* arg = PeekToken();
if (arg->Class == IdentifierClass) {
ExpectIdentifier(0, ForwardParser);
opcode->Value.Mnemonic = JZA;
opcode->Lemexe = "JZA";
}
else ExpectRegister();
}
break;
case JG:
{
Token* arg = PeekToken();
if (arg->Class == IdentifierClass) {
ExpectIdentifier(0, ForwardParser);
opcode->Value.Mnemonic = JGA;
opcode->Lemexe = "JGA";
}
else ExpectRegister();
}
break;
case JL:
{
Token* arg = PeekToken();
if (arg->Class == IdentifierClass) {
ExpectIdentifier(0, ForwardParser);
opcode->Value.Mnemonic = JLA;
opcode->Lemexe = "JLA";
}
else ExpectRegister();
}
break;
default: default:
break; break;
} }