Académique Documents
Professionnel Documents
Culture Documents
Experiment No: 02
Name of the Experiment: Introduction to Status Flags in Assembly Language.
Objective:
[2] Learning about the conditions of status flags in different instruction commands.
Introduction:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
The status flags are located in bits 0, 2, 4, 6, 7 and 11 and the control flags are located in
bits 8, 9 and 10. The other bits have no significance.
Status Flags:
There are six status flags which are Carry Flag, Parity Flag, Auxiliary Carry Flag, Zero Flag,
Sign Flag and Overflow Flag.
CF=1if there is a carry out from the MSB bit on addition or there is a borrow into the MSB
bit on subtraction; otherwise it is zero. CF is also affected by shift and rotate instructions.
PF=1 if the low byte of a result has an even number of one bits (even parity). It is 0 if the
low byte has odd number of one bits. For example, if the result of a word addition is FFFEh ,
then the low byte contains 7 one bits, so the PF=0.
Auxiliary Carry Flag (AF):
AF=1 if there is a carry out from bit 3 on addition or a borrow into bit 3 on subtraction. AF is
used in binary-coded decimal (BCD) operations.
SF=1 if the MSB of a result is 1. It means the result is negative if result is interpreted as a
signed number. SF=0 if the MSB is 0.
Class Assignment :
(a) Program 1:
CODE SEGMENT
ADD AX, BX
OR AX, BX
XOR AX, CX
NOT AX
TEST CX, DX
AND CX, AX
HLT
CODE ENDS
END
Write the values of registers and the conditions of the flag register for every step. Obtain
binary values for upper hexadecimal values and perform bit by bit operation for every step.
Then find out the values of the status flags of flag register from the obtained binary result
for each step. Compare your hand calculation with obtained result.
(b) Program 2:
CODE SEGMENT
ADD AX, CX
HLT
CODE ENDS
END
Perform this operation in single step mode and write down the values of registers and the
condition of the flag register for every step.
(c) Program 3:
CODE SEGMENT
SUB AX, BX
HLT
CODE ENDS
END
Perform this operation in single step mode and write down the values of registers and the
condition of the flag register for every step.
(d) Program 4:
CODE SEGMENT
ADD AL, BL
HLT
CODE ENDS
END
Perform this operation in single step mode and write down the values of registers and the
condition of the flag register for every step.
(e) Program 5:
CODE SEGMENT
INC AL
HLT
CODE ENDS
Perform this operation in single step mode and write down the values of registers and the
condition of the flag register for every step.
Home Assignment:
Run the following code in single step mode and write down the values of registers and the
condition of the flag registers for every step.
ORG 100h
.CODE
MAIN PROC
MOV AX, 4000H;
ADD AX, AX;
SUB AX, 0FFFFH;
NEG AX;
INC AX;
MOV AH, 4CH;
INT 21H;
MAIN ENDP
END MAIN