2

I have to write a program in MIPS assembly (32bits) checking whether fixed point decimal number can be written accurately in ieee754.
I know the structure of float, hence i do it like:

  1. split number with comma into integer and fractional part
  2. convert them separately into integers (take first to left multiply by 10 and add next)
  3. shift register with this int right untill it is zero (to know number of bits)

However, the problems starts if the program gets number with let's say 3 leading ones and then we have 40 zeroes. It still can be written accurately but is impossible to detect in my program (as i store ints as 32bit numbers). And so my question is:

  • How to write properly part with changing single digits into integers?

To recall, I have to perform 2 operations: multiply everything i have by 10 and then add another digit

Can it be done by shifting everything step by step and then indicating overflow on every 4 registers?
(if ov==1 then shift higher reg left and put one?)
Maybe there is a better way using let's say hi and low register from multiplication procedure?

Appreciate any help:)

Vasili Syrakis
  • 9,321
  • 1
  • 39
  • 56
Piotr_iOS
  • 129
  • 1
  • 7
  • 1
    it's hard to understand and imagine what you're doing. Please rephrase it. If you need to check whether a decimal number can be written accurately in ieee754, just check if the fractional part is a power of 2 or not is enough. For example 5.125 can be represented exactly in binary because `0.125 = 2^-3` which is a power of 2 while 5.123 is not – phuclv May 26 '14 at 18:18
  • Code looks as follows: – Piotr_iOS May 26 '14 at 21:51
  • why are you insisting on doing 128-bit math? Why don't read as string and check if the fractional part is a power of 2? Or at least if your fixed-point number has 64 bits or less in the fraction part, no need to do 128-bit operations – phuclv May 27 '14 at 02:25
  • the int part doesn't relate anything to whether it can be represented exactly in binary floating-point – phuclv May 27 '14 at 02:28
  • 128 i needed for number as: 1 and 125 0es, Howerer i just handed the project, Thanks for answers and comments:) – Piotr_iOS May 28 '14 at 14:27

0 Answers0