# Convert a number in a string of 0 and 1's in IEEE754 Format. single or double precision.

Is that possible in MASM?
LVL 10
###### Who is Participating?

Commented:
The floating-point registers are 80 bits long.   You use the "extended" floating point format for 80 bit values.

Do you mean convert the text representation of a real number into a IEEE ?

If so, I'd first get the algorithm to work in C,  the basic idea is:

repeat  get a character until its not a space

if it's a '+', skip it,  if it's a '-' set a minus flag, then skip it

tot = 0.0

while its a digit: multiply tot by 10.0, add in new digit.

if it's a dot:  { mul := 0.1; multiply digit by "mul"< add to total; get next character; divide mul by 10.0 }

if the negative flag is set, negate the number.

----

FIRST get this algorithm going in C, THEN work on translating it to asm.  Or cheat and peek at the asm code and write something very similar but not so C-compiler output -looking.
0

Commented:
http://www.public.iastate.edu/~sarita/ieee754/ie4.html

and this one
http://web.mit.edu/sunsoft_v6.1/SUNWspro/DOC5.0/lib/locale/C/html/common/ug/ncg_math.doc.html

these will clarify the format for you.

sure, the conversion is possible in ASM. if you need specific help, tell me where.
0

Author Commented:
Well what I actually need is the assembler code. I know is a little difficult.ç
If you want more points I can give you more
0

Commented:
The question doesnt make much sense.

Are you sure the input isnt like:   "123.456789"  ??

An input of "1010101001110110111101011110"  doesnt make much sense, plus it's trivial to do.

0

Commented:
dj, which is it?
do you want to convert "123.4567" to "011101010111000101011101010011" ?
0

Author Commented:
YES I want that...
0

Author Commented:
AH In single and double precision.
0

Commented:
well, if i understand it correctly, you want kind of floating-point-emulation.
you want to convert the number to IEEE754 format on your own.

the links i provided before have most of the info required, and i did find some C code in the linux kernel that looks like what you're trying to do.

It sure does look like alot of work.
0

Author Commented:
yeah lot of work.
0

Commented:
It's under 50 instructions.

0

Author Commented:
as I am an assembly newbiew I dont know how to make these 2 functions. But If you want I have 4000 points for you  or more if you want : I will buy more poiints is neccesary . Beause after understanding these 2 functions I should understand anything
0

Commented:
So write the bleeping thing in C following the very broad hints above.   We can't do all the work for you.

0

Commented:
Hi, here's the actual code to convert binary format to IEEE single precision:

-----------

.model medium
.586
.stack 100h
.data

binary db ?

.code

start:
finit
mov esi,binary
lodsb
mov ah,al
mov edi,7
xor edx,edx
@EXPONENT:
lodsb
cmp al,48
je @SKIP_EXPONENT
mov ebx,1
mov ecx,edi
shl ebx,cl
@SKIP_EXPONENT:
dec edi
jnl @EXPONENT
mov al,dl
sub al,127
push ax
mov edi,1
xor ebx,ebx
push ebx
fild dword ptr[esp]
pop ebx
@FACTOR:
lodsb
cmp al,48
je @SKIP_FACTOR
fld1
mov ebx,1
mov ecx,edi
shl ebx,cl
push ebx
fild dword ptr[esp]
pop ebx
fdivp st(1),st(0)
@SKIP_FACTOR:
inc edi
cmp edi,23
jl @FACTOR
fld1
pop ax
mov ebx,1
mov cl,al
shl ebx,cl
push ebx
fild dword ptr[esp]
pop ebx
fmulp st(1),st(0)
cmp ah,48
je @SKIP_SIGNUM
fldz
fld1
fsubp st(1),st(0)
fmulp st(1),st(0)
@SKIP_SIGNUM:

end start

-----------

the result is stored in ST(0)

regards,
Kate
0

Commented:
Well to be actual :)) it's much rather like (for value of -100.5):

.586
.model flat
.data

binary db '11000010110010010000000000000000'

.code

start:
finit
mov esi,offset binary
lodsb
mov ah,al
mov edi,7
xor edx,edx
@EXPONENT:
lodsb
cmp al,48
je @SKIP_EXPONENT
mov ebx,1
mov ecx,edi
shl ebx,cl
@SKIP_EXPONENT:
dec edi
jnl @EXPONENT
mov al,dl
sub al,127
push ax
mov edi,1
xor ebx,ebx
push ebx
fild dword ptr[esp]
pop ebx
@FACTOR:
lodsb
cmp al,48
je @SKIP_FACTOR
fld1
mov ebx,1
mov ecx,edi
shl ebx,cl
push ebx
fild dword ptr[esp]
pop ebx
fdivp st(1),st(0)
@SKIP_FACTOR:
inc edi
cmp edi,23
jl @FACTOR
fld1
pop ax
mov ebx,1
mov cl,al
shl ebx,cl
push ebx
fild dword ptr[esp]
pop ebx
fmulp st(1),st(0)
cmp ah,48
je @SKIP_SIGNUM
fldz
fld1
fsubp st(1),st(0)
fmulp st(1),st(0)
@SKIP_SIGNUM:
mov ax,4C00h
int 21h

end start

regards,
Kate
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.