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
SUMMARY

The Overflow (OV) flag in the 8051 microcontroller's Program Status Word (PSW) is set based on the results of arithmetic operations. Specifically, for addition, if the result of adding two positive numbers yields a negative result (indicated by a '1' in the 8th bit), the OV flag is set to 1. Conversely, for subtraction, if the result falls outside the range of -128 to 0, the OV flag is also set. The behavior of the OV flag is determined by the carry-out from bit 6 or bit 7 during these operations.

PREREQUISITES
  • Understanding of 8051 microcontroller architecture
  • Familiarity with binary arithmetic and signed numbers
  • Knowledge of Program Status Word (PSW) in microcontrollers
  • Experience with assembly language programming for the 8051
NEXT STEPS
  • Study the 8051 microcontroller's arithmetic instructions (ADD, SUBB, INC, DEC)
  • Learn about signed number representation in binary systems
  • Explore the implications of overflow in embedded systems programming
  • Review the official 8051 documentation on Program Status Word (PSW)
USEFUL FOR

Embedded systems developers, microcontroller programmers, and anyone working with arithmetic operations in the 8051 architecture will benefit from this discussion.

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   Reactions: 1 person

Similar threads

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