create helper function to handle label offsets
This commit is contained in:
parent
16e52a9421
commit
fd165aae47
10
src/encode.c
10
src/encode.c
@ -26,9 +26,15 @@ void setBits(word* wrd, uint8_t lsb, uint8_t msb, word value) {
|
||||
*wrd |= (value << lsb) & mask;
|
||||
}
|
||||
|
||||
int calculateLabelOffset(char *label, int wordArrIndex, symboltable *st){
|
||||
int labelAddress = st.get(label);
|
||||
int currInstrAddr = wordArrIndex * 4;
|
||||
int totalOffset = labelAddress - currInstrAddr;
|
||||
return totalOffset;
|
||||
}
|
||||
|
||||
// Generates assembled code based on the two-pass assembly method
|
||||
word encodeBranch(a64inst_instruction *instr) {
|
||||
word encodeBranch(a64inst_instruction *instr, int wordArrIndex) {
|
||||
word wrd = 0;
|
||||
|
||||
switch (instr->data.BranchData.BranchType) {
|
||||
@ -214,7 +220,7 @@ word *encode(a64inst_instruction insts[], int instCount, st* table) {
|
||||
// Labels are handled in the first pass and used for addressing.
|
||||
break;
|
||||
case a64inst_BRANCH:
|
||||
arr[index] = encodeBranch(&inst);
|
||||
arr[index] = encodeBranch(&inst, index);
|
||||
index++;
|
||||
default:
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user