This is my code:
global main
extern printf
extern scanf
section .text
main:
push rbp
mov rbp, rsp
mov rax, 42
push rax
lea rsi, [rbp-8]
mov rdi, formatNumScanf
xor rax, rax
call scanf wrt ..plt
mov rax, [rbp-8]
mov rdi, formatNumPrintf
mov rsi, rax
xor rax, rax
call printf wrt ..plt
mov rsp, rbp
pop rbp
section .rodata
formatNumPrintf: db '%ld', 10, 0
formatNumScanf: db '%ld', 0
It erros with a seg fault when calling scanf with [rbp-8] address, that is the top of the stack.
It is strange that if i push two registers onto the stack at the beggining, it works as expected.
What am i doing wrong?