LAB MANUAL # 03
Practicing/ Implementation of Flag Registers
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 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 to 0. (This
flag takes the value of the most significant bit.)
6. Interrupt enable Flag (IF): when this flag is set to 1 CPU reacts to interrupts from external
devices.
7. 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.
8. Overflow Flag (OF): An overflow indicates that the result has exceeded the capacity of the
machine.
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.
Example 2:
MOV BL,11111100b
MOV DH,11111000b
ADD BL, DH
Example 3:
MOV AL, 66d
MOV CL, 69d
ADD CL, AL
Example 4:
MOV AL, -12
MOV BL, +18
ADD BL, AL
Describe briefly:
1. What is Emulator and how it helps a hardware/embedded system designer?
2. What is the difference between machine code and assembly language?
3. Define Purpose of IP register?
4. Write down the purpose of AX, BX, CX and DX Registers?
5. How flags in a microprocessor help a hardware designer?
Lab Tasks
Practice and Execute the following tasks CLO [1]
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)
Task 2
Add two numbers in hex, 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)
Task 3
Check out the status of flags for the above 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.
Example 2:
MOV BL,11111100b
MOV DH,11111000b
ADD BL, DH
Example 3:
MOV AL, 66d
MOV CL, 69d
ADD CL, AL
Example 4:
MOV AL, -12
MOV BL, +18
ADD BL, AL