flat assembler
Message board for the users of flat assembler.
 flat assembler > Examples and Tutorials > FPU example with accuracy up to 8 digits
Author
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
10 Mar 2015, 18:53
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 15324
Location: Bigweld Industries
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?
11 Mar 2015, 01:10
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 . about the fnop.. I just put it in for no reason o.o
11 Mar 2015, 20:11
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------Blog General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

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