Created
December 3, 2012 21:47
-
-
Save tuttlem/4198408 to your computer and use it in GitHub Desktop.
fpu - printing floating points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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