I tried to use printf
within assembly code to print some floats (doubles to be precise), but unfortunately it doesn't work.
Code (Intel syntax)
global start
extern exit
extern printf
section .data
x dq 3.14
format db '%f',0
section .text
start:
default rel ;64-bit uses realtive addressing
mov rbp, rsp
and rsp, 0xFFFFFFFFFFFFFFF0 ;stack alignment
movsd xmm0, [x]
lea rdi, [format]
mov rax, 1
call printf
mov qword[rsp], 0
call exit
To build I use
nasm seven.asm -fmacho64 --prefix _
ld seven.o -o seven -arch x86_64 -lc -e _start -macosx_version_min 10.6
And the output is simply 0.000000
I have Macbook Pro 2013 with Intel Core i5 processor, OS X El Capitan
EDIT
Thanks to you guys, the answer is nasm
bug, which appears somewhere in 2.11.06-2.11.08 version, causing everrything in data section to be overwritten except last instruction. And the soulution was to revert to 2.11.05.