flat assembler
Message board for the users of flat assembler.

 Index > Windows > Creating a constant float from a string
Author
 Thread
NanoBytes

Joined: 02 Jun 2011
Posts: 57
Location: Iowa, United States
NanoBytes 02 Oct 2011, 18:24
Hey guys, I realize that what I am asking is daunting and fairly complex (As I have learned from the past week or so). I am trying to create a procedure that will alow me to simulate a constant float throught the use of strings
Code:
`stdcall makeFloat, "3.21"    `

The process that I was is as follows: first read the integral part of the string, which is "3", load it into the floating point stack, then read the decimal part and add it onto the integral part of the number. Well, this is all theoretical, the task was to complex for me to create a working process, and I was woundering if you guys could help me. My issue is with the decimal part, this part needs to be read backwards, meaning that you start reading from the end of the string and move tward the begining. Here is an example
Code:
```Value = (1)+Value*0.1 = 1.0
Value = (2)+Value*0.1 = 2.1
Value = Value*0.1 = 0.21
```

The numbers in parenthesis are the numbers read from the string. After the loop is over you would, in theory, add the value onto the integer value previosly read. Like I said, the task is complex, could any of you provide me with a procedure that will do this, or al least the floating point part of the string.

_________________
He is no fool who gives what he cannot
keep to gain what he cannot loose.
02 Oct 2011, 18:24
LocoDelAssembly
Your code has a bug

Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Oct 2011, 18:56
Quote:

My issue is with the decimal part, this part needs to be read backwards
Why is that? Wouldn't the following pseudo-code do the work as well?
Code:
```num= load_integer_part()
divisor = 10.0
for each fractional digit in forward direction do
num = num + ascii_to_float(digit) / divisor
divisor = divisor * 10
od    ```
I don't guarantee high quality conversions though, check fasm's sources to get a better implementation.
02 Oct 2011, 18:56
NanoBytes

Joined: 02 Jun 2011
Posts: 57
Location: Iowa, United States
NanoBytes 02 Oct 2011, 20:22
Hmmm, I like that, much simpler than I presumed, thanks, Ill try it
02 Oct 2011, 20:22
bitRAKE

Joined: 21 Jul 2003
Posts: 3511
Location: vpcmipstrm
bitRAKE 02 Oct 2011, 20:25
Using FBLD / FBSTP would be an easy lesser alternative. Multiple digits can be converted simultaneously and then a single division used to scale integer based on decimal point.

http://www.website.masmforum.com/tutorials/fptute/fpuchap6.htm
02 Oct 2011, 20:25
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals 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

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

Website powered by rwasa.