flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > FPU example with accuracy up to 8 digits

Author
Thread Post new topic Reply to topic
CampTheBoss



Joined: 02 Feb 2015
Posts: 42
Location: A chair
FPU example with accuracy up to 8 digits
Hey, it's me. I just want to show you the latest project I have done; I used the FPU to calculate division up to 8 digits. Here is the source if you want to have a look at it.

Code:

format PE console 6.0
include 'win32a.inc'
entry start

section '.data' data readable writeable
format_f db "%2.8f",10,0
val1 dd 1,0
val2 dd 4,0
decnum dd 1110000.0,0
decnum2 dd 0.2,0
divnum dd 1000000.0,0

section '.text' code readable executable
start:
push 5
finit
fild dword[esp]
fiadd dword[val1]
fst st1
fmul st0,st1
fiadd dword[val2]
fmul st0,st0
fadd dword[decnum]
fadd dword[decnum2]
fdiv dword[divnum]
fnop    ;Mnemonic for "FPU no operation"
sub esp,4
fstp qword[esp]
push format_f
call [printf]
invoke ExitProcess,0

section '.idata' import data readable
library msvcrt,'msvcrt.dll',\
        kernel,'kernel32.dll'

import msvcrt,\
       printf,'printf'

import kernel,\
       ExitProcess,'ExitProcess'




If there is anything i should improve, give me feedback Smile
Post 10 Mar 2015, 18:53
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14604
Location: Planet Dirt
One thing to note about single precision floating point numbers in IEEE754 format is that they don't provide 8 digits of precision. The most you can achieve is 7 decimal digits because the mantissa is only 23+1 bits.

Also, what is the purpose of the fnop?
Post 11 Mar 2015, 01:10
View user's profile Send private message Visit poster's website Reply with quote
CampTheBoss



Joined: 02 Feb 2015
Posts: 42
Location: A chair
aah is that why i always get a '15' for no reason? First about the single precision floating-point thing: i use over 8 digits so i can see the whole result, I have already read about the FPU and know about that Razz. about the fnop.. I just put it in for no reason o.o
Post 11 Mar 2015, 20:11
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.