0
votes

For both of them my output is 1000 0000 (80h). Adding them in decimal is 64 + 64 = 128. 128 is in range if it is unsigned, out of range if it is signed.

So for unsigned the flags that should be set off are overflow flag (because MSB is negative when numbers added were positive) and sign flag (because MSB is 1).

For signed the overflow flag should be set off yet again (because 128 is out of range for 8 bit signed) and sign flag should be set to 1 because of MSB. The carry flag should not be set because a carry operation did not occur in the MSB bits. Is this correct? The flags set off for signed vs. unsigned in this case should be the same?

1
Yes that is correct. The cpu only does one addition, the signed/unsigned decision only determines which flags you use.Jester
Depends on the architecture. Which architecture are you programming for?fuz

1 Answers

0
votes

There's only one addition operation which sets flags for both the signed and unsigned effects of the operation. Subtraction is the same (cmp is just a subtraction that discards the result, except for the flags)

  • The V (overflow) flag captures a signed overflow.
  • The C (carry) flag captures an unsigned overflow.
  • The S (sign) flag captures the top bit of the result.
  • The Z (zero) flags is set if all the result bits are 0.

That's it. You look at different flags if you were doing an unsigned or a signed operation, depending on what you are trying to detect.