From 3b3cda2d26d6defa0a13ca6d6b709a372e7fe678 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 14 Jun 2024 20:31:08 +0100 Subject: [PATCH] Fix branch handling, not to multiply by 4 --- src/assemble.c | 2 +- src/encode.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assemble.c b/src/assemble.c index c6b19fd..59a22d2 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -43,7 +43,7 @@ static symbol_table *firstPass(a64inst_instruction *instructions, int lineCount) for (int i = 0; i < lineCount; i++) { a64inst_instruction inst = instructions[i]; if (inst.type == a64inst_LABEL) { - st_insert(table, inst.data.LabelData.label, 4 * (i - (labelCount++))); + st_insert(table, inst.data.LabelData.label, (i - (labelCount++))); } } diff --git a/src/encode.c b/src/encode.c index 2f7cc0f..13fdf17 100644 --- a/src/encode.c +++ b/src/encode.c @@ -49,7 +49,7 @@ int64_t signExtend(dword value, unsigned int n) { static int getLabelOffset(symbol_table* table, char* label, int currentIndex, int n_bits) { address target = st_get(table, label); - return signExtend((unsigned int) (target - (currentIndex * 4)), n_bits); + return signExtend((unsigned int) (target - currentIndex), n_bits); } // Generates assembled code based on the two-pass assembly method