Printing floating point numbers
segment .data
flt_fmt db " %#16.8g",0
segment .bss
print_st0: ; Print top of fp stack
pusha
pushf
push ebp ; Save old bp
mov ebp,esp ; New frame pointer
sub esp,12 ; Space for call prams
fst qword [esp+4]; Get 64 st(0) -> stack
jmp common
print_fp: ; Print EAX
pusha
pushf
push ebp ; Save old bp
mov ebp,esp ; New frame pointer
sub esp,12 ; Space for call prams
mov [esp+4], eax ; Put arg on stack/temp
fld dword [esp+4]; Put 32bit fp -> st(0)
fstp qword [esp+4]; Get 64 st(0) -> stack
common:
mov dword [esp],flt_fmt
; Format string
call printf ; call c with coerced value
leave ; pop frame
popf
popa
ret