If I have a paramter that is a real4.

and the user digits 0.987 x 10 E4

How can I retrieve the exponent in a register and then convert to 127 biased (IEEE Format)
Posted on 2005-04-13 10:04:43 by luise.valencia
look at the loop therad I have posted a link to a
floating point library

Why reinvent the wheel ?
Posted on 2005-04-13 10:16:30 by rob.rice
I cant Use FPU
Posted on 2005-04-13 10:29:43 by luise.valencia
Is the number you are converting already in real4 format?

If it is:

  mov eax, my_real4_number
  shl eax, 23
  and eax, 0FFh
  sub eax, 127

I hope you mention when you hand in this homework that I did it, I'm looking forward to getting your diploma.

Posted on 2005-04-13 11:30:57 by Mirno
SOme questions

When I pass a real4 to the assembler function. It stores it in IEEE Format?

If not could you explain me a little about the instructions.

mov eax, my_real4_number ; Moves the variable into eax register
shl eax, 23,    ; shift left 23 bits the eax register, what does it means? How does the register stays after this operation
and eax, 0ffh  ; I think this compares bit a bit the eax register with 000011111111; Why?
sub eax, 127; This is easy
Posted on 2005-04-13 12:00:42 by luise.valencia
IEEE format for a floating point number is 1 sign bit, 8 exponent bits, and 23 mantissa bits.

They are stored thus:

In order to extract the eight exponent bits from the 32 bit value, we first shift left 23 bits to remove the mantissa.

shl eax, 23
MSB -> 00000000000000000000000SEEEEEEEE <- LSB

So you can now see that the exponent bits are in bits 0 to 7, however there is still the sign bit in bit 8, in order to remove it we mask off the 8 bits at the bottom using and.

and eax, 0FFh
MSB -> 000000000000000000000000EEEEEEEE <- LSB

eax now contains the exponent part of our 32 bit floating point value.
Posted on 2005-04-13 12:08:58 by Mirno
isn't it shr eax, 23?
Posted on 2005-04-14 03:13:19 by SADE
Yes, sorry my mistake!
When ever I think of shifts I default to shift left, and solving other people's problems don't warrent my thinking properly about stuff.

Well spotted though :D

Posted on 2005-04-14 04:22:06 by Mirno