How does the Over Flow flag work in 8051 MCU ?

  • Thread starter Thread starter null void
  • Start date Start date
  • Tags Tags
    Flow Work
Click For Summary
The Overflow (OV) flag in the 8051 MCU indicates when the result of an arithmetic operation cannot be represented within the 8-bit signed number range of -128 to +127. It is set when adding two positive numbers results in a negative outcome or when adding two negative numbers results in a positive outcome. Specifically, the OV flag is triggered if there is a carry-out from bit 6 or bit 7 during addition operations. For subtraction, the OV flag is set if the result falls outside the range of -128 to 0. Understanding the behavior of the OV flag is crucial for accurate arithmetic operations in the 8051 microcontroller.
null void
Messages
102
Reaction score
1
If i have a condition like : Adding
(1100 10002)[20010] + (0011 11002)[6010] = (1 0000 0100)26010

that is how i do the normal arimethic.

But how does the 8051 does it? is it because it the carry 1 is ignored, then the output answer still withing 127 to -128 range the Over Flow Flag(OV) in Program Status Word(PSW) remain 0, error is not detected by the OV.

But when i use another example like:
1100 1010 + 1100 1010 = 1) 1001 0100;
ignoring the carry, the result is out of the 127 to -128 range so the OV will get set to report Over Flow error?Or this statement is more accurate to describe Ov:
the Overflow (OV) bit is set if there is a carry-out of bit 6 or out of bit 7

So does the following statements below determine the behavior of OV:
1. if it is Addition operation(ADD and INC instruction), if the answer is withing 127 to 0, OV = 0, else = 1
2. If it is subtraction operation(SUBB and DEC instruction), if the answer is from 0 to -128. OV = 0 else = 1

Or OV work in this way:
number with '1' at the 8th bit is consider as negative number else consider as positive;

When Adding 2 positive number the resultant number has '1' as 8th bit, being consider as negative number then OV = 1

When Adding 2 negaitve number the resultant number has '0' at 8th bit, OV = 1

If so what would happen if adding 1 negative number with 1 positive number ?Or it is the Overflow (OV) bit is set if there is a carry-out of bit 6 or out of bit 7
 
Last edited:
Engineering news on Phys.org
http://www.edsim51.com/8051Notes/8051/programStatusWord.html explains it pretty well.

The overflow flag indicates the result cannot be correctly represented by an 8 bit signed number (-128 to +127).
 
  • Like
Likes 1 person
I am trying to understand how transferring electric from the powerplant to my house is more effective using high voltage. The suggested explanation that the current is equal to the power supply divided by the voltage, and hence higher voltage leads to lower current and as a result to a lower power loss on the conductives is very confusing me. I know that the current is determined by the voltage and the resistance, and not by a power capability - which defines a limit to the allowable...

Similar threads

Replies
5
Views
9K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
4K
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K