First I'm on OS X(x86-64 set) and I use nasm.
I'm following a tutorial to asm, and I'm writing a function to reverse a string.
My problem is that I can't put byte in my resb buffer.
I have Mach-O 64-bit format does not support 32-bit absolute addresses
error. I did some research, tried a lot of things(like lea, or mov into a register first) nothing seems to solve my problem.
Below is my code and my problem is on: mov [output + rdi], eax
(I'm trying to write the reverse string of input db buffer to output resb 12 buffer) in reverseStr
label
section .data
nl db 0xa
input db "Hello world!"
section .bss
output resb 12
section .text
global start
global _main
start:
jmp _main
ret
_main:
push rbp
mov rbp, rsp
mov rsi, input
xor rcx, rcx
cld
mov rdi, $ + 15
call calculateStrLength
xor rax, rax
xor rdi, rdi
jmp reverseStr
calculateStrLength:
cmp byte [rsi], 0
je exit
lodsb
push rax
inc rcx
jmp calculateStrLength
reverseStr:
cmp rcx, 0
;je printResult
pop rax
mov [output + rdi], eax
dec rcx
inc rdi
jmp reverseStr