I have an assembly hello world program for Mac OS X that looks like this:
global _main
section .text
_main:
mov rax, 0x2000004
mov rdi, 1
lea rsi, [rel msg]
mov rdx, msg.len
syscall
mov rax, 0x2000001
mov rdi, 0
syscall
section .data
msg: db "Hello, World!", 10
.len: equ $ - msg
I was wondering about the line lea rsi, [rel msg]
. Why does NASM force me to do that? As I understand it, msg
is just a pointer to some data in the executable and doing mov rsi, msg
would put that address into rsi
. But if I replace the line lea rsi, [rel msg]
with , NASM throws this error (note: I am using the command nasm -f macho64 hello.asm
):
hello.asm:9: fatal: No section for index 2 offset 0 found
Why does this happen? What is so special about lea
that mov
can't do? How would I know when to use each one?