flat assembler
Message board for the users of flat assembler.

Index > Main > FPU to and from ASCII

Author
Thread Post new topic Reply to topic
eiforall



Joined: 21 Sep 2005
Posts: 5
eiforall 22 Sep 2005, 00:02
Hi, I am looking how to convert ASCII to singe 32 bit and double 64 bit precision float point values store it in the FPU. Do some computation … and then take and convert it back to ACSII.

I know I can do this yet I think I would do it rather an unoptimized and inefficient way.

So does any one have very good FASM FPU to and from ASCII code I can learn form?
Post 22 Sep 2005, 00:02
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 22 Sep 2005, 02:15
eiforall,

You can use Raymond's excellent FPULIB which can found here:

http://www.ray.masmcode.com/

It's coded in MASM, but with Vortex's tools, you can use the .lib file.

In the FPULIB you will find FpuFLtoA and FpuAtoFL

hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 22 Sep 2005, 02:15
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 22 Sep 2005, 05:34
it's not necessarily to create lib, because fpulib is open-source
Post 22 Sep 2005, 05:34
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 22 Sep 2005, 11:01
farrier wrote:
eiforall,

You can use Raymond's excellent FPULIB which can found here:

http://www.ray.masmcode.com/

It's coded in MASM, but with Vortex's tools, you can use the .lib file.

In the FPULIB you will find FpuFLtoA and FpuAtoFL

hth,

farrier


The algorithms used have a lost of precision up to 12 bits for extreme numbers like 1.0e4000
There is a better algo that use a table of powers of 10 ,i don´t have links,but remember that some time ago it was posted on this forum.
Post 22 Sep 2005, 11:01
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 22 Sep 2005, 13:08
maybe somebody will need - inside the package function converting ascii string into the float in st0. i had look in masm lib on similar, but decided to write by myself as i like Smile do not run exe directly! it made for test and have int3 to stop debugger to see what a number we have in st0! Wink

regards!


Description:
Download
Filename: fpu2.4.zip
Filesize: 9.05 KB
Downloaded: 564 Time(s)


_________________
UNICODE forever!


Last edited by shoorick on 23 Sep 2005, 05:56; edited 1 time in total
Post 22 Sep 2005, 13:08
View user's profile Send private message Visit poster's website Reply with quote
eiforall



Joined: 21 Sep 2005
Posts: 5
eiforall 22 Sep 2005, 15:58
Thank you very much!

Now I am trying to port FPULIB to Fasm. Well always some little things. First it has uID feature witch make it covert form memory or fpu. Some macros like .if .endif …

I am just surprised no one done clean float point conversions in fasm.

Sorry shoorick I tried your program using Microsoft debugger and it showed that the register was something other then 12.1, which I typed. On second try Microsoft goofed up and started 2 debuggers and they where competing 45% of cpu on one and 45% of cpu on the other my mouse when jerky till I realized that they where running in the back ground windowless. Please make a ‘to and form’ converter then one can see how it is done without so much trouble.

Which debugger did you use?
Post 22 Sep 2005, 15:58
View user's profile Send private message Reply with quote
eiforall



Joined: 21 Sep 2005
Posts: 5
eiforall 22 Sep 2005, 18:28
Hi!

Look at:
http://board.flatassembler.net/topic.php?t=234

I guess I could have gotten it there in the first place.

I changed the code a little bit do reduce rigid syntax. Can enter – 123.23 instead of always –123.23 (now ignores spaces before and after sign instead of giving 0)

But I still cant enter –12.23e34 … the E!

Does any one know how to do make an fexp command?
I mean take st(1)^st(0)?

So I also find some student’s homework exponential project. Does any one have any ideas how I can check which one would be best? I need to measure size and speed of the code. Any more float point to/form ASCII are welcome since I sort of collect them now Smile
Post 22 Sep 2005, 18:28
View user's profile Send private message Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 22 Sep 2005, 18:56
Here are two methods for raising 2^st(0), its MASM code but should be easy to convert. The first is probably the faster (credits to bitRAKE for it).

Code:
fPow2 MACRO ; 2^st, 98 clocks
sub esp,16
fist dword ptr [esp+12]
fld1
fstp tbyte ptr [esp]
fisub dword ptr [esp+12]
mov eax,[esp+12]
add [esp+8],eax
f2xm1
fld1
fadd 
fld tbyte ptr [esp]
fmul
add esp,16
EndM    

Code:
fPow2 MACRO ; 2^st
fld st
frndint
fsub st(1),st
fld1
fscale
fxch
fstp st
fxch
f2xm1
fld1
fadd
fmul
EndM    


Using that you can implement the two following macroinstructios
Code:
fExp MACRO ; e^st, 99 clocks
fldl2e
fmul
fPow2
EndM    

Code:
fPow MACRO ; st^st(1), 200 clocks
fyl2x
fPow2
EndM    


Attached are numerous additional trigonmetric macroinstructions. Again all MASM, but easy to convert.


Description:
Download
Filename: maths.asm
Filesize: 4.88 KB
Downloaded: 499 Time(s)

Post 22 Sep 2005, 18:56
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 23 Sep 2005, 05:00
eiforall
i'm using olly. commonly this function was written in self-education and was not used in real: when it was compiled by masm fwait-s were inserted there automatically - i'll try to play with it again Smile and translate comments Wink
Post 23 Sep 2005, 05:00
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 23 Sep 2005, 05:58
look at the new version above - it is same just you can run it without debugger - sprintf used to exact output it into second edit. and has translated comments. regards!
Post 23 Sep 2005, 05:58
View user's profile Send private message Visit poster's website Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 23 Sep 2005, 06:31
With Raymonds permission, here is the FPULIB in DLL form which can be used easily from the FASM. Also included are the files, other than source, I used to build the DLL. Download the full package and Help file from:

http://www.ray.masmcode.com/

Assemble command:
_____________________________________________________________________________________________
ML.EXE /c /coff /Cp /nologo /I"$I" FPU.asm
_____________________________________________________________________________________________

Link command:
_____________________________________________________________________________________________
LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /DLL /DEF:FPU.def /LIBPATH:"$L" /OUT:"FPU.dll" FPU.obj
_____________________________________________________________________________________________


In you import section include the following:

library fpu, 'c:\Program Files\Radasm\masm\projects\fpu\fpu.dll'

import fpu, \
FpuAtoFL, 'FpuAtoFL', \
FpuAdd, 'FpuAdd', \
FpuFLtoA, 'FpuFLtoA', \
FpuComp, 'FpuComp'

for each function you want, or include them all.

hth,

farrier


Description:
Download
Filename: FPULIBDL.ZIP
Filesize: 3.6 KB
Downloaded: 447 Time(s)


_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 23 Sep 2005, 06:31
View user's profile Send private message 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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.