The original FPULIB (library of floating point math functions) was primarily designed for the beginners in assembly programming who had some need for such math functions but did not yet have the opportunity lo learn how to use the FPU and its instructions.

Some feedback proved that a little knowledge can be dangerous. Some users were loading too many FPU registers themselves; called functions then resulted in failure because an insufficient number of free registers were remaining to accomplish the task.

A modification was issued earlier this year to blindly free any register(s) required by the function, regardless of whether it contained valid data or not. This would have no effect on the beginner using strictly the lib functions. However, it would prevent "FPU stack overflow" errors due to inadvertant use of the FPU registers by "intermediate" programmers. The drawback for that latter group was that valid data on the FPU could be trashed.

Lately, it also became evident that some assembler HLL instructions would blindly trash FPU registers to perform their task. Although such action seems to be generally accepted as "fair game", an alternate version of the FPULIB has thus been prepared to avoid such blind trashing. Again, this modified version would have no effect on the beginner using strictly the lib functions. The only drawback is the added overhead to save the FPU registers and restore them.

This version may be an advantage for intermediate users who may want to use some of the library functions without any fear of loosing valuable data in FPU registers, and without any need of preserving such data themselves.

The only restriction of this modified version is that the ST7 register must be free whenever the FPU is not the source for any parameter AND the result must be returned on the FPU. If that ST7 register is NOT free under those conditions, it would NOT be trashed but the function would fail.

This latest version also has one function more liberalized and one additional function. The FpuAtoFL function will now disregard all leading 0's and decimal trailing 0's in the count of numerical digits which is limited to 18. A string such as the following would now be converted without generating an error:


But a string such as the following would still fail, having more than 18 numerical characters starting at the first non-zero digit and up to the last non-zero digit:


The new function is FpuState. It is primarily designed for the more advanced users during program development to retrieve the content of the FPU at any time (such as after some exception or error is detected at run time). The generated string is formatted as it would appear in the accompanying .gif image when displayed in a message box. Such strings could also be accumulated in an "error" file and reviewed later.

The attached file contains all necessary files, including all source code. The bulk of the .zip file is the HELP file which has also been updated to reflect the modifications.

Posted on 2004-03-22 23:04:22 by Raymond
Can't seem to be able to attach more than one file per post.

Here's the .gif file.

Posted on 2004-03-22 23:05:57 by Raymond
And my apologies to the person who downloaded the fpulib20 file first posted. The post has been edited with the proper file. Please scrap that first one and get the proper one. Most included files should now be dated 23/03/2004.

Posted on 2004-03-22 23:51:44 by Raymond
Hello Raymond!
Since my last experience, I think that your last modification of the FpuLib is an important improvement, specially for programmers that use the FPU without care. :grin:


Posted on 2004-03-23 00:36:16 by Biterider
Hi Raymond!
first id like to thank you for the lib, its great!
but im having some trouble with the FpuFLtoA function. not shure if its my code or if its the func, but since the error returned points into the code of the lib i figured i should post it here. heres my code:


tmpdb dd 400 dup(?)

freq label qword ; are set through other func.
freqL dd ?
freqH dd ?

;FPUtmp dt ?



fild qword ptr[esp] ; st(0)=top qword on stack=cycler
fild freq ; st(0)=freq=f, st(1)=cycler
fdivp st(1),st(0) ; st(0)=time (i know it could be reaplced with fdiv but
; this makes it more readeble =)
add esp,8 ; fix stack.
; fstp FPUtmp ; used this with the old v. of FpuLib

invoke FpuState,addr tmpdb ; see attached image for result.
invoke MessageBox,hWnd,addr tmpdb,NULL,MB_OK

invoke FpuFLtoA,0,9,addr tmpdb,SRC1_FPU or SRC2_DMEM ; this is where the err occurs.

and heres the errlog (sorry bout the swedish):

Prg: (pid=1292)
Tidpunkt: 2004-03-27 kl 11:13:31.919
Undantagsnummer: c0000005 (Access Violation)

*----> Systeminformation <----*
Datornamn: *
Anv?ndarnamn: *
Antal processorer: 1
Processortyp: x86 Family 6 Model 8 Stepping 10
Windows 2000-version: 5.0
Aktuell build: 2195
Service Pack: 4
Aktuell typ: Uniprocessor Free
Registrerad organisation: *
Registrerad ?gare: *

*----> Active program <----*
1292 PhySC.exe

(00400000 - 00407000)
(77F80000 - 77FFC000)
(79880000 - 79936000)
(77E10000 - 77E6F000)
(77F40000 - 77F79000)
(77590000 - 777DA000)
(794B0000 - 79512000)
(77130000 - 7719E000)
(70A70000 - 70AD5000)
(78000000 - 78045000)
(71710000 - 71794000)
(76B20000 - 76B5E000)
(65720000 - 65729000)
(77560000 - 77590000)

Statusdumping f?r tr?d-ID 3b4

eax=00000009 ebx=00000000 ecx=00000000 edx=00000000 esi=00401148 edi=00000111
eip=00401d9d esp=0012fba0 ebp=0012fc48 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000206

funktion: <nosymbols>
00401d81 dec1 faddp st(1),st
00401d83 d9fd fscale
00401d85 ddd9 fstp st(1)
00401d87 c3 ret
00401d88 55 push ebp
00401d89 8bec mov ebp,esp
00401d8b 81c458ffffff add esp,0xffffff58
00401d91 8b450c mov eax,[ebp+0xc] ss:00c89b2e=????????
00401d94 f7451400040000 test dword ptr [ebp+0x14],0x400 ss:00c89b2e=????????
00401d9b 7402 jz 0040a89f
FEL ->00401d9d 8b00 mov eax,[eax] ds:00000009=????????
00401d9f 50 push eax
00401da0 0fb6c0 movzx eax,al
00401da3 83f80f cmp eax,0xf
00401da6 7605 jbe 0040d5ad
00401da8 b80f000000 mov eax,0xf
00401dad 8945f0 mov [ebp+0xf0],eax ss:00c89b2e=????????
00401db0 58 pop eax
00401db1 0fb6c4 movzx eax,ah
00401db4 83f811 cmp eax,0x11
00401db7 7605 jbe 0040d5be
00401db9 b811000000 mov eax,0x11
Posted on 2004-03-27 05:28:30 by sluggo

This is the instruction you used (highlighting the flag you used for SRC2 having a value of 9):
invoke FpuFLtoA,0,9,addr tmpdb,SRC1_FPU or [b]SRC2_DMEM[/b]	; this is where the err occurs.

And, from the Help file, here's the description of the flags you can use for that parameter:
SRC2_DMEM Src2 is a pointer to a 32-bit unsigned integer
SRC2_DIMM Src2 is a 32-bit unsigned integer
By specifying the SRC2 as a pointer to a memory location, you were then trying to access data at address DS:0009.

Use the DIMM flag.

Posted on 2004-03-27 12:03:38 by Raymond
sorry, missunterstood it :o. thank you again.
Posted on 2004-03-27 13:21:56 by sluggo