user4424299
user4424299

Reputation:

Find value of struct-variable in assembly code

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?

Upvotes: 3

Views: 595

Answers (1)

Alexei Barnes
Alexei Barnes

Reputation: 268

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?

Upvotes: 5

Related Questions