aboutsummaryrefslogtreecommitdiff
path: root/tasm/src/assembler.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-11-19 20:25:29 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2023-11-19 20:25:29 +0200
commit910ad02d86672cc3020cc5df0fa451ef4dd69bfd (patch)
treed5711894ee14c62caee8f8b744cac2d28f92c87b /tasm/src/assembler.c
parent51789d2ed69515ab81bee6633bac3d94c519dc03 (diff)
downloadtri-910ad02d86672cc3020cc5df0fa451ef4dd69bfd.tar.gz
tri-910ad02d86672cc3020cc5df0fa451ef4dd69bfd.zip
implement jalr
Diffstat (limited to 'tasm/src/assembler.c')
-rw-r--r--tasm/src/assembler.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/tasm/src/assembler.c b/tasm/src/assembler.c
index 731a736..ba61045 100644
--- a/tasm/src/assembler.c
+++ b/tasm/src/assembler.c
@@ -378,9 +378,16 @@ static void fix_reloc_b(struct asm_ctx *ctx, size_t ro, size_t so)
ctx->buf[ro] = build_s(OPCODE_BRANCH, hi, fn0, rs1, rs2, lo);
}
+/* convert instruction index (as used by ctx->idx) to addresses */
+static size_t asm_addr(size_t o)
+{
+ return o * 3;
+}
+
static void fix_reloc_j(struct asm_ctx *ctx, size_t ro, size_t so)
{
- int64_t off = so - ctx->idx;
+ /* internal offsets are instruction indexes, so convert to address */
+ int64_t off = asm_addr(so) - asm_addr(ro);
tri_t t = tri_from(off);
if (tri_mask(t, 18) != t) {
fprintf(stderr, "jump offset at %llu too large\n",