0
$\begingroup$

Consider the figure in Exercise 2. If the current machine code that executes is 0x214bfffd and the values of the registers in the processor are as shown below, what is then the value of the input WD3 ? Answer as a 32-bit hexadecimal value. at = 0x00011021 v0 = 0x5234f1a0 v1 = 0x1114f111 a0 = 0xff001231 a1 = 0xffffffff a2 = 0x32252341 a3 = 0xff1245ee t0 = 0xffff12ff t1 = 0xffffffff t2 = 0xfffffff5 t3 = 0xfffff67f t4 = 0x0121ffff t5 = 0x55f7fff5 Assume that all other registers in the register file have value 0.

The tex dollar sign is interfering with the dollar signs for the reigsters so I am writing it without dollar signs.

I understand everyhting except the fact that how we can tell directly that t2 = 0xfffffff5 is a negative number? Because that is what they are saying without any explanantion in the answer sheet. I know that a number where the most significant bit is 1 is negative and vice versa positive. But most of the questions I answered tell us to that it is a 4 bit number represented by 8 bit etc which you can then obviously tell. But in this case how do we know that they t2 = 0xfffffff5= -11 and not $t2 = 4294967285?

$\endgroup$

1 Answer 1

2
$\begingroup$

how do we know that they t2 = 0xfffffff5= -11 and not $t2 = 4294967285?

We don't. They're the same number (in mod 232 arithmetic, which is what your computer uses.)

Essentially, signed or unsigned is not a property of the number. It's a property of each individual assembly instruction. Some instructions don't care about signedness, like add or sub, because treating them as signed or unsigned doesn't change the result. Other instructions do care, like mul, and these instructions usually come in two variants. Let's write two C functions that differ only in signedness of the arguments.

int64_t foo(int32_t a, int32_t b) { return (int64_t)a * b; }
uint64_t bar(uint32_t a, uint32_t b) { return (uint64_t)a * b; }

If we compile them for MIPS, we get almost the same code but with mult versus multu instructions.

foo(int, int):
    mult    $4,$5
    mflo    $3
    mfhi    $2
    jr      $31
    nop
bar(unsigned int, unsigned int):
    multu   $4,$5
    mflo    $3
    mfhi    $2
    jr      $31
    nop

If you call bar with a signed argument like bar(-11, 4), it will actually be treated as bar(4294967285, 4) because the unsignedness is baked into the bar function itself. The argument is always the binary pattern 0xfffffff5, which is just a binary pattern with no inherent meaning. If you pass this binary pattern to a function that expects an unsigned 32 bit integer, that's where the binary pattern suddenly becomes more meaningful.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.