If you're trying to figure out why your printf call sometimes crashes, check that you're zeroing out %rax before the printf call (unless you're actually printf-ing floating point numbers).
Under the 64bit ABI %rax is described as: temporary register; with variable arguments passes information about the number of vector registers used; 1st return register. The vector registers are xmm0-xmm7 and they are used when passing floating point arguments.
If you're looking for a way to get the hex representation of PI (0x400921FB53C8D4F1), this is what I used: IEEE-754 Floating-Point Conversion.
Under the 64bit ABI %rax is described as: temporary register; with variable arguments passes information about the number of vector registers used; 1st return register. The vector registers are xmm0-xmm7 and they are used when passing floating point arguments.
#============== asm.s ==============#
.data
msg: .ascii "Hello World\0"
fmt1: .ascii "%s\n\0"
fmt2: .ascii "This is pi:%.10f\n\0"
pi: .quad 0x400921FB53C8D4F1
.text
.globl _dis
_dis:
sub $8, %rsp
movq $0, %rax
movq fmt1@GOTPCREL(%rip), %rdi
movq msg@GOTPCREL(%rip), %rsi
call _printf
movsd pi(%rip), %xmm0
movq $1, %rax
movq fmt2@GOTPCREL(%rip), %rdi
call _printf
add $8, %rsp
ret
#============ mainasm.c ============#
extern void dis();
int main()
{
dis();
}
cristi:tmp diciu$ as -arch x86_64 asm.s -o asm.o
cristi:tmp diciu$ gcc mainasm.c asm.o
cristi:tmp diciu$ ./a.out
Hello World
This is pi:3.1415926500
If you're looking for a way to get the hex representation of PI (0x400921FB53C8D4F1), this is what I used: IEEE-754 Floating-Point Conversion.