Vous êtes sur la page 1sur 5

Bangabandhu Sheikh Mujibur Rahman Science & Technology University

Department of Electrical & Electronic Engineering


Laboratory Experiment Sheet
Course No: EEE 391
Course Title: Microprocessor Interfacing and System Design LAB

Experiment No: 02
Name of the Experiment: Introduction to Status Flags in Assembly Language.

Objective:

[1] Introducing status flags in Assembly Language.

[2] Learning about the conditions of status flags in different instruction commands.

Introduction:

FLAGS register is shown below:

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.

Carry Flag (CF):

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.

Parity Flag (PF):

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.

Zero Flag (ZF):

ZF=1 for a zero result and ZF=0 for a non-zero result.

Sign Flag (SF):

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.

Overflow Flag (OF):

OF=1 if signed overflow occurred, otherwise it is 0.

Class Assignment :

Write following codes and perform indicated operations:

(a) Program 1:

CODE SEGMENT

ASSUME CS:CODE, DS:CODE

MOV AX, 22B7H

MOV BX, 5A27H

MOV CX, 84C5H

MOV DX, 0000H

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

ASSUME CS:CODE, DS:CODE

MOV AX, 0FFFFh

MOV CX, 0FFFFh

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

ASSUME CS:CODE, DS:CODE

MOV AX, 8000h

MOV BX, 0001h

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

ASSUME CS:CODE, DS:CODE

MOV AL, 80h

MOV BL, 80h

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

ASSUME CS:CODE, DS:CODE

MOV AL, 0FFh

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

Vous aimerez peut-être aussi