I think the problem is that (right before you call printf
) you use the wrong instruction to pop the FPU's top onto the stack. Your comment says "...this time as double precision...", but what you actually do with fstp
is storing a single-precision value. Try fstpl
and it will store a double-precision value.
The fixed code should look something like this:
.data
fl: .float 12.412
test: .string "Result: %f\n"
.text
.global main
main:
subl $8, %esp
fld fl
fstps (%esp)
flds (%esp)
fstpl (%esp) # This line is the only one that has been changed.
pushl $test
call printf
movl $1, %eax
int $0x80