In: Computer Science
Choose two flags (bits) from the 8086 status register, also known as flags register. In your own words briefly describe the purpose of each flag and how it works
There are a total of 6 flags in the 8086 status register and they are -
1. Sign flag
2. Zero flag
3. Auxiliary carry flag
4. Parity flag
5. Carry flag
6. Overflow flag
(1) The overflow flag has 2 values either 0 or 1. It's default value is 0 whenever this flag is active its value becomes 1. This flag is used when as name suggests there is an overflow of anything, mostly when the output of the operation has more bits than the available one.
Lets Understand this with a help of example. Suppose you want to add the 2 numbers let's say 127 and 127 but using a 8 bit register. So technically 127 + 127 will be 254 but as we are using a 8 bit register so the output in binary would be 1111 1110 which will be - 2 in 2's compliment and this is a negative value. This scenario is a example of overflow as you are getting a negative value after adding 2 positive numbers os the flag will be set to 1. This flag is crucial for the system to let him know that there is some error in the code.
(2) The zero flag (Z) is one of the most crucial flags in the register. Like the overflow flag it also has 2 values that's either 0 or 1 and the default value is 0 and when the flag has to be set its value become 1. This flag is used to indicate that whether the output or the result of any arithmetic operation is zero or not. If the result is zero the flag sets to 1 else it remains 0. Let understand this with the help of an example -
MVI B 10 ##(load 10H in register B)
SUB B (B = B– B)
This will result in 0 as the result which as a result will set the zero flag to 1.