I am trying to convert a double to a string on the stack from x86_64 assembly code:
bs.code += isa.movsd(registers.xmm0, MemRef(registers.rsp))
bs.code += isa.pop(registers.rax)
bs.code += isa.push(registers.rbp)
bs.code += isa.mov(registers.rbp, registers.rsp)
bs.code += isa.sub(registers.rsp, 100)
bs.code += isa.and_(registers.rsp, -16)
bs.code += isa.mov(registers.rdi, registers.rsp)
bs.code += isa.mov(registers.rsi, <address of "%i\0">)
bs.code += isa.mov(registers.rax, <address of sprintf in libc>)
bs.code += isa.call(registers.rax)
The program segfaults at call(rax)
with
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a2919b in *__GI___overflow (f=0x7fffffffb5d0, ch=9698128) at genops.c:248
warning: Source file is more recent than executable.
248 return _IO_OVERFLOW (f, ch);
I think sprintf
has to be called specially because it uses variable arguments, so can anybody advise on the proper way to do this from assembly?