Professional Documents
Culture Documents
LAB MANUAL # 03
FLAG REGISTER
8086 has 16 flag registers among which 9 are active. The purpose of the FLAG register is to
indicate the status of the processor. It does this by setting the individual bits called flags. There are
two kinds of FLAGS;
Status FLAGS and Control FLAGS. Status FLAGS reflect the result of an operation executed by
the processor. The Control FLAGS enable or disable certain operations of the processor.
1. Carry Flag(CF): holds the carry out after addition or borrow after subtraction. Also indicates
error condition.
2. Parity Flag (PF): this flag is set to 1 when there is even number of one bits in result, and to
0 when there is odd number of one bits.
3. Auxiliary Flag(AF): The auxiliary carry holds the carry (half-carry) after addition or the
borrow after subtraction between bit positions 3 and 4 of the result.
4. Zero Flag (ZF): set to 1 when result is zero. For non-zero result this flag is set to 0.
5. Sign Flag (SF): set to 1 when result is negative. When result is positive it is set to0. (This
flag takes the value of the most significant bit.)
7. Interrupt enable Flag (IF): when this flag is set to 1 CPU reacts to interrupts from external
devices.
8. Direction Flag (DF): this flag is used by some instructions to process data chains, when
this flag is set to 0 - the processing is done forward, when this flag is set to 1the processing
is done backward.
9. Overflow Flag (OF): An overflow indicates that the result has exceeded the capacity of the
machine.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Describe briefly:
AX Register (16-Bits): It holds operands and results during multiplication and division
operations. All IO data transfers using IN and OUT instructions use A register (AL/AH or
AX). It functions as accumulator during string operations.
BX Register (16-Bits): It holds the memory address (offset address), in Indirect Addressing
modes.
CX Register (16-Bits): It holds count for instructions like: Loop, Rotate, Shift and String
Operations.
DX Register (16-Bits): It is used with AX to hold 32 bit values during Multiplication and
Division. It is used to hold the address of the IO Port in indirect IO addressing mode.
Task 1
What effect on Conditional Flags will happens after the addition of 10110001 and 10101011? (write
state of each of the flag as observed, note values of flags after execution of every single instruction
in the program).
Solution:
Step1:
In this first step we loaded the program for execution and as it loaded into memory it sets “IF
(Interrupt Flag)” to 1 and shows it is enabled.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Step2:
After that in next step, the command “MOV” command is executed and value is loaded in “AX”
register in form of Hex value and value of all Flags remains set to zero except “IF”.
Step3:
In next step, we add 10101011b into AX. Only the parity flag and Auxiliary Flag is set to 1 because
the number of One’s in the answer is 5 (odd number) this shows that my system is odd. All other
flags are set to 0.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Step 4:
In next step, only the value of “IP” changes all the rest remains the same.
Step 5:
In the last step , only PF and AF is active and set to “1” and all the rest set to zero.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Task 2
Add two numbers in BIN, save the result in AX register and observe the value of flags.
1000 0000 0000 0000
1100 1000 0000 0000
(write state of each of the flag as observed, note values of flags after execution of every single
instruction in the program
Solution:
Step1:
In First step I used “BX” register to store values and loaded the program for execution with “IF” set
to 1.
Step2:
In next step command is executed and value is moved into “BX” register but no changes in the
values of flag registers.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Step3:
In the next step, the value 1100100000000000 is added to “BX” and “CF (Carry Flag)” and “OF
(Overflow Flag)” and “PF” are changes value and set to “1”. In the last step we add AX and BX.
so all the flags are again set to 0. In this step Cary flag is set to 1 because result of the addition is
14800H only 4800 is shown and 1 is the carry. Also Overflow flag is set to 1 indicating that the result
has exceeded the capacity of the machine. Also Parity flag is set to 1 because number of One’s in
the answer is 3 (odd number) this shows that my system is odd. All other flags are set to 0.
Step4:
In the last step the final result is stored in “AX” and there are no changes except “IF” set to 0.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Task 3
Check out the status of flags for the following examples?
Example 1:-
MOV DX, 126FH;
ADD DX, 3465H;
MOV BX, 0FFFFH;
ADD BX, 1;
Use Single Step and observe changes in flags after executing every single statement. Also, convert
the numbers to binary and prove the results(manually) as observed using emulator.
Solution:
Step1:
In first step we move 12 6FH into DX. All flags are set to 0 except “IF”.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Step2:
In step 2 Parity and Auxiliary flags are set to the 1.
Step3:
In step we move FFFFH into BX the flag values are same as in step 2.
Step4:
In last step we add 1H into BX and see that Zero and Cary flags are set to 1. Zero flag indicates
that BX contains 0 value and Carry flag indicates that carry obtained as a result of addition.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Example 2:-
MOV BL,+8
MOV DH,+4
ADD BL,DH
Solution:
In This Example the value with + sign are loaded into registers and displayed as “00” and their
addition makes changes in the “Parity Flag (PF)” and “Zero Flag (ZF)” as set to “1”.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Example 3:-
MOV AL, +66
MOV CL, +69
ADD CL,AL
Solution:
Step1&2:
In first two steps values are loaded to respective registers only and all flags are set to “0”.
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Step3:
In last step, the “Parity Flag” and “Zero Flag” are set to 1.
Example 4:-
MOV AL, -12
MOV BL, +18
ADD BL,AL
Solution:
After successful execution of the code Sign Flag is set to 1 showing that answer is some negative
value
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
Example 5:-
MOV AH, -30
MOV DL, +14
ADD DL, AH
Solution:
After successful execution of the code Sign and Parity flags are set to 1
NAME: Sheikh Abuzar Amjad
REG NO: 19-CP-6
The End