I'm trying to print the first argument to my 64-bit NASM program. I'm getting Segmentation fault (core dumped).
; L26.asm
section .data
fmt db '%s', 10, 0
section .text
global main
extern printf
main:
mov rdi, fmt
; +8 to skip the first argument, which is the program name
mov rsi, [rsi + 8]
xor rax, rax
call printf
; Return from the main function
ret
I'm creating an executable like so:
nasm -f elf64 -o L26.o L26.asm && gcc -no-pie -o L26 L26.o
And running like so:
./L26 foo
I'm very new to assembly (and C). Answers online and ChatGPT are making it seem like it should be this simple to print arguments (just offsetting rsi). I'd appreciate any guidance.