From ce34f27fbd053d2d1ed524ba27a9b67fe98b698f Mon Sep 17 00:00:00 2001 From: GDBWNV <93523315+GDBWNV@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:33:09 +0100 Subject: [PATCH] data processing immediate --- src/{symboltable.c => symboltable.h} | 10 ++++- src/twopassassembly.c | 65 +++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 14 deletions(-) rename src/{symboltable.c => symboltable.h} (81%) diff --git a/src/symboltable.c b/src/symboltable.h similarity index 81% rename from src/symboltable.c rename to src/symboltable.h index fb448c1..cd2037c 100644 --- a/src/symboltable.c +++ b/src/symboltable.h @@ -19,8 +19,14 @@ struct st { // add new node to the end void st_add(st table, void* key, void* value) { node n = {key, value, table.tail}; - (*(table.tail)).next = &n; - table.tail = &n; + if (table.head == NULL) { + table.head = &n; + table.tail = &n; + } + else { + (*(table.tail)).next = &n; + table.tail = &n; + } } // returns the pointer to key of the specified node, or null, if it does not exist diff --git a/src/twopassassembly.c b/src/twopassassembly.c index d6194a8..48090b9 100644 --- a/src/twopassassembly.c +++ b/src/twopassassembly.c @@ -1,15 +1,8 @@ +# include "global.h" +# include "a64instruction.h" +# include "symboltable.h" //generates assembled code based on two pass assembly method -void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){ - //TODO: - //generate symbol table based on inputted assembly code and labels - for(int i=0; itype==LABEL){ - // symbol table stuff here - } - } -} word assembleBranch(a64inst_instruction *instr, int ){ word binInstr = 0; @@ -39,15 +32,63 @@ word assembleBranch(a64inst_instruction *instr, int ){ } } -void firstPass(a64inst_instruction instrs[], int numInstrs){ +st* firstPass(a64inst_instruction instrs[], int numInstrs){ //TODO: // -iterate over instructions, adding to symbol table // create symbol table and map labels to addresses/lines + struct st table; + for(int i=0; i