diff --git a/misc/test.asm b/misc/test.asm index e12f7e6..5a59bf4 100644 --- a/misc/test.asm +++ b/misc/test.asm @@ -1,45 +1,16 @@ -.org 0x100 -.db msg "Hello, world!", 0 -.db more_stuff "AAAA", 0 +;.org 0x100 +;.db msg "Hello, world!", 0 +;.db more_stuff "AAAA", 0 +copy r7, 45 +cmp r8, 45 -copy r1, more_stuff ;//B0 = 10110000 -copy more_stuff, 45 -loop: - cmp r1, 0 - jz loop - add r1, 1 -mov r1, 5 ; move the immediate value 5 into r1 -add r1,5 ; add 5 into r1 -int 21 ; maybe that will call some string drawing BIOS-like routine -ret -; form YYYY YYXX - Y opcode, X modifier -; nop: 0000 0000 -; copy: 0000 01XX -; add: 0000 10XX - | Perhaps running these will clear any overflow -; addc: 0000 11XX - | or under flow flags if no errors occur. -; sub: 0001 00XX - | jz should clear the zero flag. -; subb: 0001 01XX - | -; call: 0001 1100 - Always call [imm16] -; jmp: 0010 0000 - Always jmp [imm16] (No short jumps) -; jz: 0010 0100 - Always jz [imm16] (no short jumps) -; cmp: 0010 11XX -; push: 0011 11XX -| pop / push imm16/imm8 | reg -; pop: 0100 00XX -| - -; -; imm8 imm16 reg -; mov reg, imm16|reg -; add reg, imm16|reg -; int imm16 -; db [label] 'String data here' (Null byte is added implicatly by the assemblier) -; -; enum Type { -; Op, -; Reg, -; Imm16, -; Imm8 -; } -; struct Token { -; enum Type type; -; char *value; -; } \ No newline at end of file +;copy r1, 45 ;//B0 = 10110000 +;copy 2, 45 +;loop: +; cmp r1, 0 +; jz loop +; add r1, 1 +;mov r1, 5 ; move the immediate value 5 into r1 +;add r1,5 ; add 5 into r1 +;int 21 ; maybe that will call some string drawing BIOS-like routine +;ret \ No newline at end of file diff --git a/src/parser.c b/src/parser.c index 1d4eead..9106792 100644 --- a/src/parser.c +++ b/src/parser.c @@ -132,7 +132,7 @@ void HandleAssemblerDirective(void) { } } -//REG XXX0 0XXX +//REG XXX0 0XXX 1010 1111 //Constant XXX0 1XXX //Address XXX1 0XXX void HandleOperation(void) { @@ -144,7 +144,7 @@ void HandleOperation(void) { printf("[%#05X] %s ", ProgramCounter, inst->lexeme); - Memory[ProgramCounter] |= GetInstructionMask(inst->op, inst->parameter_one); + Memory[ProgramCounter] = GetInstructionMask(inst->op, inst->parameter_one); ProgramCounter++; @@ -158,7 +158,7 @@ void HandleOperation(void) { if (inst->parameter_one & Reg) { //Encode the register number here. - Memory[ProgramCounter - 1] |= PeekToken()->type - 29; + Memory[ProgramCounter - 1] |= (PeekToken()->type - 29) & 0x07; printf("%s ", PeekToken()->lexeme); } else if (inst->parameter_one & Address || inst->parameter_one & Constant) { @@ -170,7 +170,8 @@ void HandleOperation(void) { exit(1); } - Memory[ProgramCounter - 1] |= 0x10;//0b00010000; + if (inst->op == CMP) Memory[ProgramCounter - 1] |= 0x10;//0b00010000; + Memory[ProgramCounter] = 2 >> symbol->address & 0xFF; Memory[ProgramCounter + 1] = symbol->address & 0xFF; @@ -211,7 +212,8 @@ void HandleOperation(void) { exit(1); } - Memory[ProgramCounter - 1] |= 0x10;//0b00010000; + if (inst->op == CMP) Memory[ProgramCounter - 1] |= 0x10;//0b00010000; + Memory[ProgramCounter] = 2 >> symbol->address & 0xFF; Memory[ProgramCounter + 1] = symbol->address & 0xFF; @@ -221,8 +223,8 @@ void HandleOperation(void) { Memory[ProgramCounter - 1] |= 0x08; //0b00001000; int* value = PeekToken()->value; - Memory[ProgramCounter] = 2 >> *value &0xFF; - Memory[ProgramCounter + 1] = *value &0xFF; + Memory[ProgramCounter] = 2 >> *value & 0xFF; + Memory[ProgramCounter + 1] = *value & 0xFF; printf("%s ", PeekToken()->lexeme); } diff --git a/src/token.c b/src/token.c index c511b6e..5155ca2 100644 --- a/src/token.c +++ b/src/token.c @@ -39,7 +39,7 @@ TokenClass GetTokenClass(TokenType type) { void FreeToken(Token* token) { if (!token) return; - if (token->value && token->type >= STRING) free(token->value); + if (token->value && (token->type >= STRING || token->type == NUMBER)) free(token->value); free(token); } \ No newline at end of file