0

I am brushing up on my assembly cause I would like to build a compiler without llvm, just plain assembly. I forgot the basics. I am on MAC OS with an x8664 machine. I would like to loop, keeping the counter inside a register, and build the array using the value inside the register as an offset. I keep getting either a mismatch operator error, or a Mach-O 64-bit format does not support 32-bit absolute addresses. I put DEFAULT REL so technically I can avoid the use of rel

; this is what I want
xor rbx, rbx
mov rax, 1
; now load this inside array
; this is all the stuff I tried, nothing works
mov [final+rbx], rax ; 1
mov byte[final+rbx], rax
mov byte[final+bl], al
mov [final+bl], al
mov [final+bl], rax


section .bss
array resb 3



none of these work. It seems kinda odd, as in this answer link the author uses this mov [array+rsi], al ; store the new value into array. I have no idea how to solve this, could someone help?

  • 1
    You can avoid `REL` but you still need RIP-relative addressing for PIE. I don't know what the mac toolchain defaults to. Either use RIP-relative addressing or make a non-PIE (if you can). Also what's `final` and `bl` is not a valid base. – Margaret Bloom Nov 25 '22 at 18:04
  • 2
    Unfortunately `rip`-relative only allows `rip` and an offset. So `[rip+final+rbx]` is not valid (which is what you'd expect `default rel` to generate). You should first load the array address into a register e.g. `lea rdi, [final]` then you can do `mov [rdi+rbx], al`. PS: use `array` if that is your symbol. – Jester Nov 25 '22 at 18:06
  • thank you very much guys. The name in my code is final, but here for clarity I have chosen array. I ended mixing them up confusing everybody. Sorry for that. Thanks again. – not_here_to_play Nov 25 '22 at 19:55

0 Answers0