Solved

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

Posted on 2005-04-08
280 Views
Is that possible in MASM?
0
Question by:djhex

LVL 5

Expert Comment

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

LVL 10

Author Comment

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

LVL 22

Expert Comment

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

LVL 5

Expert Comment

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

LVL 10

Author Comment

YES I want that...
0

LVL 10

Author Comment

AH In single and double precision.
0

LVL 22

Accepted Solution

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

LVL 5

Expert Comment

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

LVL 10

Author Comment

yeah lot of work.
0

LVL 22

Expert Comment

It's under 50 instructions.

0

LVL 10

Author Comment

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

LVL 22

Expert Comment

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

0

LVL 10

Expert Comment

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

LVL 10

Expert Comment

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

## Featured Post

### Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…