0

What does the Two's Complement Overflow Flag means when you are doing a "Logical Shift Left", "Logical Shift Right" or an "Arithmetic Shift Right" in assembly?

3
  • Which microprocessor are you referring to? Commented Nov 20, 2013 at 22:40
  • AVR 8bit microcontrollers Commented Nov 20, 2013 at 23:03
  • but I want to know what that flag means in general for any 8bit or 16bit microprocessor Commented Nov 20, 2013 at 23:05

1 Answer 1

2

This may depend upon the microprocessor and you need to check the respective manual for the instruction set. If you read the AVR instruction set manual, it explains what happens to the status register bits.

For LSL, V (two's complement overflow) is determined by:

V: N ⊕ C (For N and C after the shift)
N: Set if MSB of the result is set; cleared otherwise.
C: Set if, before the shift, the MSB of Rd was set; cleared otherwise.

V is the exclusive OR of the negative bit (highest order bit in the 8-bit value after shift) and the carry bit. Semantically, it means that the upper two bits of your value, before the shift, had opposite parity.

For LSR, V (two's complement overflow) is determined by:

V: N ⊕ C (For N and C after the shift)
N: 0
C: Set if, before the shift, the LSB of Rd was set; cleared otherwise.

In this case, since N is 0, then V is simply the complement of C. It's bit value is therefore the opposite of whatever the least significant bit value was for the 8-bit value before the shift. Semantically, if it's set, it means that the upper two bits of your value, before the shift, had opposite parity.

For ASR, V (two's complement overflow) is determined by:

V: N ⊕ C (For N and C after the shift)
N: Set if MSB of the result is set; cleared otherwise.
C: Set if, before the shift, the LSB of Rd was set; cleared otherwise.

Semantically, ASR treats the 8-bit value as if it were signed in that it preserves the highest order (sign) bit. So N indicates that the value is a negative 8-bit value (before and after the shift, since it's preserved). The V bit will be set if the value shifted is negative and it was even (lowest order bit was clear) before the shift, and it will be set if the shifted value is positive and it was odd (lowest order bit was set) before the shift. Otherwise, V will be clear.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.