The main function will now write out the output of the parser.

This commit is contained in:
2022-08-29 21:23:02 +00:00
parent 6c7b8d5356
commit 3c7056c5e6
4 changed files with 22 additions and 34 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
assm assm
obj/ obj/
bin/ bin/
*.bin
+2 -2
View File
@@ -2,8 +2,8 @@
.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, r3 ;1000 1111 cmp r8, msg ;1000 1111
add r4, r1 add r4, 0x42
sub r1, r8 sub r1, r8
int 20 int 20
jz 45 jz 45
+18 -11
View File
@@ -1,3 +1,4 @@
#include <bits/types/FILE.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -21,22 +22,28 @@ 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("[T: %i][C: %i] '%s' ", t->type, t->token_class, t->lexeme); // 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);
FILE* program = fopen("program.bin", "w+b");
fwrite(image, 1, image[2] + image[3], program);
fclose(program);
free(source_code); free(source_code);
} }
-20
View File
@@ -32,8 +32,6 @@ int Expect(int, ...);
int ExpectTokenClass(int, ...); int ExpectTokenClass(int, ...);
const Symbol* GetSymbol(char*); const Symbol* GetSymbol(char*);
List* SymbolsTable; List* SymbolsTable;
void WriteMemory(unsigned char value, int location);
void WriteMemoryORMask(unsigned char mask, int location);
unsigned int HeapTop = 4; unsigned int HeapTop = 4;
unsigned int ProgramCounter = 0; unsigned int ProgramCounter = 0;
unsigned char Heap[HIGHMEMORY]; unsigned char Heap[HIGHMEMORY];
@@ -481,22 +479,4 @@ int ParserAtEnd(void) {
Token* PeekToken(void) { Token* PeekToken(void) {
return TokensList->content[CurrentToken]; return TokensList->content[CurrentToken];
}
void WriteMemory(unsigned char value, int location) {
if (location > HIGHMEMORY) {
fprintf(stderr, "[Error] Exceeded memmory size\n");
exit(1);
}
Memory[location] = value;
}
void WriteMemoryORMask(unsigned char mask, int location) {
if (location > HIGHMEMORY) {
fprintf(stderr, "[Error] Exceeded memmory size\n");
exit(1);
}
Memory[location] |= mask;
} }