How does the Over Flow flag work in 8051 MCU ?

  • Thread starter Thread starter null void
  • Start date Start date
  • Tags Tags
    Flow Work
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 4K views
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