• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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

Is that possible in MASM?
Can you please help me. Thanks in advanced
0
djhex
Asked:
djhex
  • 5
  • 4
  • 3
  • +1
1 Solution
 
mzvikaCommented:
try this link
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
 
djhexAuthor 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
 
grg99Commented:
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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
mzvikaCommented:
dj, which is it?
do you want to convert "123.4567" to "011101010111000101011101010011" ?
0
 
djhexAuthor Commented:
YES I want that...
0
 
djhexAuthor Commented:
AH In single and double precision.
0
 
grg99Commented:
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
 
mzvikaCommented:
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
 
djhexAuthor Commented:
yeah lot of work.
0
 
grg99Commented:
It's under 50 instructions.

0
 
djhexAuthor 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
 
grg99Commented:
So write the bleeping thing in C following the very broad hints above.   We can't do all the work for you.

 
0
 
_Katka_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
  add edx,ebx
@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)
  faddp st(1),st(0)
@SKIP_FACTOR:
  inc edi
  cmp edi,23
  jl @FACTOR
  fld1
  faddp st(1),st(0)
  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
 
_Katka_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
  add edx,ebx
@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)
  faddp st(1),st(0)
@SKIP_FACTOR:
  inc edi
  cmp edi,23
  jl @FACTOR
  fld1
  faddp st(1),st(0)
  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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now