From 999f36facd4dd95bacf730a7b9b7357381126669 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Tue, 11 Jun 2024 23:19:04 +0100 Subject: [PATCH] Fix bugs to make code compile. Code now compiles --- src/symboltable.h | 49 ----------------- src/twopassassembly.c | 121 +++++++++++++++++++++--------------------- 2 files changed, 60 insertions(+), 110 deletions(-) delete mode 100644 src/symboltable.h diff --git a/src/symboltable.h b/src/symboltable.h deleted file mode 100644 index cd2037c..0000000 --- a/src/symboltable.h +++ /dev/null @@ -1,49 +0,0 @@ -#include - -typedef struct st st; - - - -typedef struct { - const void* key; - void* value; - node* prev; - node* next; -} node; - -struct st { - node* head; - node* tail; -}; - -// add new node to the end -void st_add(st table, void* key, void* value) { - node n = {key, value, table.tail}; - 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 -void* st_search(st table, void* key) { - return nodeSearch(table.head, key); -} - -void* nodeSearch(node* n, void* key) { - if (n != NULL) { - if ((*n).key == key) { - return (*n).value; - } - else { - return nodeSearch((*n).next, key); - } - } - else { - return NULL; - } -} \ No newline at end of file diff --git a/src/twopassassembly.c b/src/twopassassembly.c index b5dccae..e6899d5 100644 --- a/src/twopassassembly.c +++ b/src/twopassassembly.c @@ -1,32 +1,33 @@ #include "global.h" #include "a64instruction/a64instruction.h" #include "symboltable.c" -//generates assembled code based on two pass assembly method +#include +#include +// Generates assembled code based on the two-pass assembly method -word assembleBranch(a64inst_instruction *instr){ +word assembleBranch(a64inst_instruction *instr) { word binInstr = 0; - binInstr += (5^28); //101 start of branch instr - switch (instr->data.BranchData.BranchType) - { + binInstr += (5 << 28); // 101 start of branch instr + switch (instr->data.BranchData.BranchType) { case a64inst_UNCONDITIONAL: - //000101 - //25-0: sign extended simm26 + // 000101 + // 25-0: sign extended simm26 binInstr += instr->data.BranchData.processOpData.unconditionalData.unconditionalOffset; break; case a64inst_REGISTER: - //10000 - //11111 - //000000 - //9-5: address from register - //0000 - binInstr += ((instr->data.BranchData.processOpData.registerData.src)^5); + // 10000 + // 11111 + // 000000 + // 9-5: address from register + // 0000 + binInstr += ((instr->data.BranchData.processOpData.registerData.src) << 5); break; case a64inst_CONDITIONAL: - // 01010100 + // 01010100 // 25-5: sign extended offset // 4-0: 0{condition} - binInstr += ((instr->data.BranchData.processOpData.conditionalData.offset)^5); + binInstr += ((instr->data.BranchData.processOpData.conditionalData.offset) << 5); binInstr += instr->data.BranchData.processOpData.conditionalData.cond; break; default: @@ -35,43 +36,43 @@ word assembleBranch(a64inst_instruction *instr){ return binInstr; } -st* firstPass(a64inst_instruction instrs[], int numInstrs){ - //TODO: +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