From: Justas Butkus on
Hello all,

Could you help me with this kind of situation:

I am using Turbo Assembler v3.2 on x86, DOS (Windows).

I have a list of numbers on a text file in a way like this:
<number1>;<number2>;...;<numberN>

But I ran into a problem - how could I read a <number> and convert it
into a floating point number. I have a list of ASCII symbols and have
no clue, where to start with conversion.

I think, it could be a little bit easier with integers - then I would
just read it one symbol per time, and then I reach a semicolon, I just
stop, take the number of characters read and multiply it by order of
magnitude:
123 := 3*1 + 2*10 + 1*100
But is this correct, and if - yes, how could I start working with
floating point numbers?


I will appreciate any help.


--
JB
From: Wolfgang Kern on

Justas Butkus asked:


> I am using Turbo Assembler v3.2 on x86, DOS (Windows).

> I have a list of numbers on a text file in a way like this:
> <number1>;<number2>;...;<numberN>

> But I ran into a problem - how could I read a <number> and convert it
> into a floating point number. I have a list of ASCII symbols and have
> no clue, where to start with conversion.

> I think, it could be a little bit easier with integers - then I would
> just read it one symbol per time, and then I reach a semicolon, I just
> stop, take the number of characters read and multiply it by order of
> magnitude:
> 123 := 3*1 + 2*10 + 1*100
> But is this correct,

Yes, this is one way to convert decimal to binary, hope you be aware
of limit/valid checks and ASCII-filtering.

> and if - yes, how could I start working with
> floating point numbers?

Could be the same for the integer-part (until DP.), but after this
the decimal digits need to be converted into binary fractions which
are defined as 2^(-n) values ie: "3.75"

0011.1100 bin = 3.75 dec
^^ ^^-------- .25 [2^(-2)]
|| '--------- .5 [2^(-1)]
|'----------- 1.0 [2^(0) ]
'------------ 2.0 [2^[+1]]

If you like to do this 'manualy'(good for learning) then you need to
find the magnitude of the fraction and covert it the same way as the
integer (at another store location) and then either check/subtract
against/with all powers of 2 (starting with -1, ending with -n-1)
and set/clear the associeted bits, or use a divide by contants, or
use a LookUpTable conversion, or ....

Another method is to just see the whole figure as an integer and
let the DP-position just become an 10^x exponent [aka FixPoint].

To feed the FPU with this 10^x needs conversion to make the whole
thing 2^n based again. Not to fast nor very precise, but often seen.

see also: FBLD FBSTP FSCALE and friends.
__
wolfgang



From: Phil Carmody on
Justas Butkus <butkus.justas(a)gmail.com> writes:
> Hello all,
>
> Could you help me with this kind of situation:
>
> I am using Turbo Assembler v3.2 on x86, DOS (Windows).
>
> I have a list of numbers on a text file in a way like this:
> <number1>;<number2>;...;<numberN>
>
> But I ran into a problem - how could I read a <number> and convert it
> into a floating point number. I have a list of ASCII symbols and have
> no clue, where to start with conversion.
>
> I think, it could be a little bit easier with integers - then I would
> just read it one symbol per time, and then I reach a semicolon, I just
> stop, take the number of characters read and multiply it by order of
> magnitude:
> 123 := 3*1 + 2*10 + 1*100
> But is this correct, and if - yes, how could I start working with
> floating point numbers?
>
>
> I will appreciate any help.

Look at the source to atof() from any free library.
It's a pretty simple state machine. While you've not
reached a decimal point, just multiply by 10 and add;
else add a multiple of an ever-decreasing value. If
you meet an 'e' then be prepared to multiply by 10
to the power of the integer value that follows.

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration