0

I am currently learning about arithmetic operations for Intel 8086 assembly language. I was trying to figure out manually after the below code what would the status of flat bits specially overflow flag and sign flag bit and why?

MOV AX, 0xFFFF            ;
MOV BX, 0x0               ;
SUB BX,AX                 ;

Here as the number the stored value is in 2's complement stored in BX 0001H. What would be the status of sign and overflow flags! Also I am confused the 16th bit as stored in two's complement is zero. As the value stored in 2's complement is 0001H (in BX), it is out of range as decimal of it is -65535 being out of range of -32768 to 32767 (signed range for 16bit operation).So the overflow flag should be 1. And the sign flag should be 0 as the 16th bit is zero. But it shouldn't be the case as it is a negative number!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Show us your attempt at answering this. – Nate Eldredge Jul 30 '22 at 19:40
  • Thanks for the feedback. I described my attempts to solve it. – ABIR HASSAN Jul 30 '22 at 19:54
  • 1
    Where are you getting -65535 from? 0xFFFF represents -1. And 0 minus -1 equals +1. – Zac67 Jul 30 '22 at 20:44
  • 1
    `0-65535` in 16-bit wraps to `1` unsigned. OF is based on interpreting the *input* as signed as well, so `0 - (-1) => +1` without signed overflow. – Peter Cordes Jul 30 '22 at 20:52
  • 2
    Does this answer your question? [Why is the overflow flag not being set in this example?](https://stackoverflow.com/questions/64272052/why-is-the-overflow-flag-not-being-set-in-this-example) - it covers misinterpreting the input as large positive when it's actually negative like here. also [Understanding sign and overflow flag in assembly](https://stackoverflow.com/q/14155145) is subtraction-based. – Peter Cordes Jul 30 '22 at 20:57
  • 1
    [Sign, Carry, and Overflow Flag (Assembly)](https://stackoverflow.com/q/23990071) is also good, with a visual example. Also [Carry Flag, Auxiliary Flag and Overflow Flag in Assembly](https://stackoverflow.com/q/19301498) – Peter Cordes Jul 30 '22 at 20:58
  • Remember that assembly has no knowledge of whether your data is intended to be signed or unsigned. Flags are updated after instructions that do mathematics, like `add` or `sub` (which flags an instruction affects, if any, is a property of the instruction itself.) The flags are updated as if your data is signed, regardless of whether it actually is. – puppydrum64 Dec 15 '22 at 14:34

0 Answers0