The first 6 arguments go in registers rdi, rsi, rdx, rcx, r8, r9 respectively. My understanding is that if there's a seventh argument or more, they should be pushed onto the stack. The following code works:
mov rdi, format_string
mov rsi, 1
mov rdx, 2
mov rcx, 3
mov r8, 4
mov r9, 5
call printf
But when I add a seventh argument:
mov rdi, format_string
mov rsi, 1
mov rdx, 2
mov rcx, 3
mov r8, 4
mov r9, 5
push 6
call printf
add rsp, 8
The code generates a segmentation fault. What am I doing wrong?