How does the Over Flow flag work in 8051 MCU ?

  • Thread starter null void
  • Start date
  • Tags
    Flow Work
In summary: It is set if there is a carry-out of bit 6 or bit 7 during addition, or if there is a borrow into bit 7 during subtraction. It is not set if the result is within this range.In summary, the Overflow (OV) bit is set if there is a carry-out of bit 6 or bit 7 during addition or a borrow into bit 7 during subtraction. It indicates that the result cannot be correctly represented by an 8 bit signed number and is not set if the result is within the range of -128 to +127.
  • #1
null void
102
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
  • #2
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

1. How does the Over Flow flag work in 8051 MCU?

The Over Flow flag in the 8051 MCU is a single bit flag that is set or cleared depending on the result of arithmetic or logic operations. It is located in the PSW (Program Status Word) register and is used to indicate when an arithmetic operation results in an overflow or carry. This flag is set when the result of an operation exceeds the range of the processor's data type, and it is cleared when the operation is within the data type's range.

2. What is the purpose of the Over Flow flag in 8051 MCU?

The Over Flow flag is used to detect when an arithmetic operation has resulted in an overflow or carry. This is important for ensuring accurate and reliable calculations, especially when dealing with large numbers. The flag can also be used to implement error handling and exception handling in programs.

3. How is the Over Flow flag set and cleared in 8051 MCU?

The Over Flow flag is set when an arithmetic operation, such as addition or multiplication, results in a value that is too large to be represented in the data type being used. It is cleared when the operation is within the data type's range. The flag can also be manually set or cleared by the programmer using specific instructions in the assembly language.

4. What happens when the Over Flow flag is set in 8051 MCU?

When the Over Flow flag is set, it indicates that an overflow or carry has occurred during an arithmetic operation. This means that the result of the operation is outside of the data type's range and may not be accurate. In this case, the programmer should implement error handling or exception handling to ensure the correct execution of the program.

5. How can I check the status of the Over Flow flag in 8051 MCU?

The Over Flow flag can be checked by reading the PSW (Program Status Word) register. The flag is located in bit 2 of the register, so a bit mask can be used to extract its value. Alternatively, some instructions in the assembly language, such as JC (Jump if Carry) and JNC (Jump if Not Carry), can be used to directly check the status of the Over Flow flag and perform conditional branching based on its value.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top