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)

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)

look at the loop therad I have posted a link to a

floating point library

Why reinvent the wheel ?

floating point library

Why reinvent the wheel ?

I cant Use FPU

Is the number you are converting already in real4 format?

If it is:

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

Mirno

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.

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

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

IEEE format for a floating point number is 1 sign bit, 8 exponent bits, and 23 mantissa bits.

They are stored thus:

MSB -> SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM <- LSB

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.

They are stored thus:

MSB -> SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM <- LSB

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.

isn't it shr eax, 23?

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

Mirno

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

Mirno