Fixed a bug where CMP REG, REG wouldn't get encoded and a disassembler bug related to said CMP bug.

This commit is contained in:
2022-08-29 19:29:34 +00:00
parent 5f437b6869
commit 6c7b8d5356
4 changed files with 26 additions and 16 deletions
+3 -3
View File
@@ -2,9 +2,9 @@
.db msg "Hello, world!", 0 .db msg "Hello, world!", 0
.db more_stuff "AA", 0 .db more_stuff "AA", 0
copy r7, msg ; // copy r7, msg ; //
cmp r8, 45 ;1000 1111 cmp r8, r3 ;1000 1111
add r4, 30 add r4, r1
sub r1, 69 sub r1, r8
int 20 int 20
jz 45 jz 45
jmp msg jmp msg
+3 -2
View File
@@ -32,8 +32,9 @@ void Disassemble(unsigned char image[HIGHMEMORY]) {
IsRegisterPattern(instruction & 0x07, parameter1); IsRegisterPattern(instruction & 0x07, parameter1);
unsigned char parameterType = instruction & 0x18; unsigned char parameterType = instruction & 0x18;
if (!parameterType) { if (parameterType == REGMASK) {
IsRegisterPattern(Image[position], parameter2); IsRegisterPattern(Image[position + 1], parameter2);
position += 2;
} else if (parameterType == CONSTMASK) { } else if (parameterType == CONSTMASK) {
snprintf(parameter2, sizeof(char) * 31, "%d", Image[position + 1] + Image[position + 2]); snprintf(parameter2, sizeof(char) * 31, "%d", Image[position + 1] + Image[position + 2]);
position += 3; position += 3;
+10 -10
View File
@@ -21,19 +21,19 @@ int main(int argc, char* args[]) {
List* list = GenerateTokenList(source_code); List* list = GenerateTokenList(source_code);
// for(int i = 0; i < list->size; i++) { for(int i = 0; i < list->size; i++) {
// Token* t = (Token*) list->content[i]; Token* t = (Token*) list->content[i];
// if (t->type == LineEnd) { if (t->type == LineEnd) {
// if (i - 1 >= 0 && ((Token*) list->content[i - 1])->type != LineEnd) if (i - 1 >= 0 && ((Token*) list->content[i - 1])->type != LineEnd)
// printf("\n"); printf("\n");
// continue; continue;
// } }
// printf("[%i] '%s' [%i] ", t->type, t->lexeme, t->token_class); printf("[T: %i][C: %i] '%s' ", t->type, t->token_class, t->lexeme);
// if (t->type == LABEL) printf("* "); if (t->type == LABEL) printf("* ");
// } }
unsigned char* image = ParseTokens(list); unsigned char* image = ParseTokens(list);
Disassemble(image); Disassemble(image);
+10 -1
View File
@@ -199,7 +199,16 @@ void HandleRegisterBasedOpcode(unsigned char instruction, unsigned char mask) {
Memory[ProgramCounter + 1] = *value & 0xFF; Memory[ProgramCounter + 1] = *value & 0xFF;
AdvanceParser(); AdvanceParser();
} else { }
else if (token->token_class == Reg) {
Memory[ProgramCounter] = (PeekToken()->type - R1) & 0x07;
AdvanceParser();
ProgramCounter++;
return;
}
else {
fprintf(stderr, "[Error] Expected operand, got %s\n", token->lexeme); fprintf(stderr, "[Error] Expected operand, got %s\n", token->lexeme);
exit(1); exit(1);
} }