Skip to content

Instantly share code, notes, and snippets.

@tuttlem
Created December 3, 2012 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuttlem/4198408 to your computer and use it in GitHub Desktop.
Save tuttlem/4198408 to your computer and use it in GitHub Desktop.
fpu - printing floating points
; compiled on linux 64 bit using the following
;
; nasm -f elf32 print.asm -o print.o
; gcc -m32 print.o -o print
;
[bits 32]
section .text
extern printf
global main
main:
; load pi into st(0)
fldpi
; prepare some space on the stack
sub esp, 8
; to be able to push st(0) in there
fstp qword [esp]
; get the string format on the stack as well
push format
; print the string
call printf
; repair the stack
; 4 bytes memory address (for the format)
; + 8 bytes memory for the float
; =========
; 12 bytes
add esp, 12
; exit without error
xor eax, eax
ret
section .data
format: db "%.20g",10,0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment