3

I'm preparing for my exam of computer architecture this year and I'm solving some exams from previous years, but I have this one exercise which I can't solve. I'm asked to find the value of g.z when the following C and assembly-code is given:

enter image description here

You can see in the assembly-code that the value $0x41300000 is written to z, but what could this be in decimal? I tried to find some pattern between the values of g and g + 4 (x and y), but I can't seem to find anything.

Any ideas?

1 Answers1

5

This looks to me like typical IEEE754 (thanks for the correction) floating point number representation, on modern hardware a floating point number is represented in memory via a sign bit, a series of bits for an exponent, and the remaining bits in a mantissa (which in this case is dictated by the IEEE).

The value of z in this case is the hex 0x4130 0000, which comes out to 11.

Here is how you work that out for both an example of 1.0 (0x3F80 0000) and for your value below that.

0x3    F    8    0    0    0    0    0
 b0011 1111 1000 0000 0000 0000 0000 0000

 sign     = b0                               = 0         = +
 exponent = b0111 1111                       = 127 - 127 = 0
 mantissa = b000 0000 0000 0000 0000 0000    = 0   + 1   = 1
          = 1 * 2^0 = 1 * 1 = 1



0x4    1    3    0    0    0    0    0
 b0100 0001 0011 0000 0000 0000 0000 0000

 sign     = b0                               = 0          = +
 exponent = b1000 0010                       = 130  - 127 = 3
 mantissa = b011 0000 0000 0000 0000 0000    = .375 + 1   = 1.375
          = 1.375 * 2^3 = 1.375 * 8 = 11

source: How are floating point numbers are stored in memory?

Community
  • 1
  • 1
Alexei Barnes
  • 268
  • 1
  • 9
  • @PieterVerschaffelt Sorry, I made a mistake calculating the mantissa, somehow I shifted the bits in my head. The correct answer for z is 11, not 14. – Alexei Barnes May 10 '16 at 17:42
  • That is not correct. C does not enforce a specific floating point representation. – too honest for this site May 10 '16 at 19:16
  • 1
    You can see the IEEE754 bit patterns of a float in C only because you're running C on a platform that uses the standard IEEE754 representation for floating point. (i.e. nearly every modern processor with hardware floating point.) – Peter Cordes May 10 '16 at 20:57
  • @PeterCordes thanks, you are correct. Not sure why I was lazy and put C as if C standardized that, but I've reworded the answer to be accurate. – Alexei Barnes May 11 '16 at 20:26