I have a problem with write a call of printf on x86_64 linux assembler. If i try print a double value when rsp % 0x10 != 0
, printf a fall down with segfault.
Look to my code (nasm syntax):
[bits 64]
global _start
extern printf
extern pow
section .data
printf_format db '%lf', 10, 0
section .text
_start:
mov rbp, rsp
sub rsp, MEM_VAL
mov rax, 0x4000000000000000
mov qword [rsp], rax
movsd xmm0, qword [rsp]
mov rdi, printf_format
mov rax, 1
call printf
mov rax, 60
mov rdi, 0
syscall
If MEM_VAL = 0x10, 0x20, ... , 0x100, ...
all is good. Code work. But with another value code is down with segfault. Why?
I compile and link with this:
nasm -f elf64 ex.asm
ld -lc -lm -m elf_x86_64 -I/lib/ld-linux-x86-64.so.2 ex.o -o ex
Taking this opportunity, I will ask you, where I can read a spec to C calling convention in x86_64 linux? I know that it is an fastcall, but i can't understand a thinness like this.