Hex subtraction and overflow/carry flags

  • Thread starter Thread starter nwilkins259
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 8K views
nwilkins259
Messages
9
Reaction score
0
Signed hex subteaction of 71-A9, i get C8. My question is whether the flags carry/borrow or overflow occurred. Its a positive number and a neg number so can it be overflow? Or is it the same as subtracting a neg number...?
 
Physics news on Phys.org
It will set the carry flag, for the 8051 anyway. The processor cannot tell if an operand is signed or unsigned.
 
Isn't the first thing the comp does when it sees minus is to take the 2's compliment? Wouldn't that make this 71+57, which woulld not carry but would be overflow?
 
When you mentioned a carry bit, I jumped into the assembly language level of thought. I reference an 8051, because it’s a common 8-bit machine.

The instructions:

mov A, #113
subb A, #-87

are the same as

mov A, #0x71
subb A, #0xA9

You are on the right track. In this case, when the assembler "sees" the negative sign, it represents the value using 2’s complement.

The result of the above instructions is that the A-register will contain 0xC8 (or, using 2's complement in reverse, -56), the carry bit is set, and the overflow bit is also set because the result would have been 200 which cannot be represented in an 8-bit 2’s complement system.