Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

CS Department Computer Organization && Assembly language

LAB 4

FLAG STATUS REGISTER

UMT, Lahore Page 1


CS Department Computer Organization && Assembly language

IN THIS LAB U WILL LEARN:

Conditional Flags
• Carry flag
• Sign flag
• Overflow flag
• Zero flag
• Auxiliary flag
• Parity flag

Control Flags
• Trap flag
• Interrupt flag
• Directional flag

LAB TASK

UMT, Lahore Page 2


CS Department Computer Organization && Assembly language

Flag Register
The 8086 flag register contents indicate the results of computation in the ALU. It also contains
some flag bits to control the CPU operations.

A flag can only take on the values 0 and 1. We say a flag is set if it has the value 1.

A 16 flag register is used in 8086. It is divided into two parts.

(a) Condition code or status flags

(b) Machine control flags

The condition code flag register is the lower byte of the 16-bit flag register. The condition code
flag register is identical to 8085 flag register, with an additional overflow flag.

The control flag register is the higher byte of the flag register. It contains three flags namely
direction flag (D), interrupt flag (I) and trap flag (T).

The complete bit configuration of 8086 is shown in the figure.

X X X X O D I T S Z X AC X P X CY

S- Sign Flag: This flag is set, when the result of any computation is negative.

Z- Zero Flag: This flag is set, if the result of the computation or comparison performed by the
previous instruction is zero.

P- Parity Flag: This flag is set to 1, if the lower byte of the result contains even number of
1’s.

C- Carry Flag: This flag is set, when there is a carry out of MSB in case of addition or a
borrow in case of subtraction.

T- Tarp Flag: If this flag is set, the processor enters the single step execution mode.

I- Interrupt Flag: If this flag is set, the mask able interrupt are recognized by the CPU,
otherwise they are ignored.

D- Direction Flag: This is used by string manipulation instructions. If this flag bit is ‘0’, the
string is processed beginning from the lowest address to the highest address, i.e., auto
incrementing mode. Otherwise, the string is processed from the highest address towards the
lowest address, i.e., auto incrementing mode.

UMT, Lahore Page 3


CS Department Computer Organization && Assembly language

AC-Auxiliary Carry Flag: This is set, if there is a carry from the lowest nibble, i.e, bit
three during addition, or borrow for the lowest nibble, i.e, bit three, during subtraction.

O- Over flow Flag: This flag is set, if an overflow occurs, i.e, if the result of a signed
operation is large enough to accommodate in a destination register. The result is of more than 7-
bits in size in case of 8-bit signed operation and more than 15-bits in size in case of 16-bit sign
operations, and then the overflow will be set.

Flags When its Set(1)

CF—Carry Flag when there is an unsigned overflow

PF---Parity Flag when there is even number of one bits in result

AF---Auxiliary Flag when there is an unsigned overflow for low nibble (4 bits)

ZF---Zero Flag when result is zero

SF---Sign Flag when result is negative

TF---Trap Flag Used for on-chip debugging

IF—Interrupt Enable Flag - when this flag is set to 1 CPU reacts to interrupts from external devices

DF---Direction Flag 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

OF---Overflow Flag when there is a signed overflow

UMT, Lahore Page 4


CS Department Computer Organization && Assembly language

LAB TASK
Execute the following Programs in Turbo Debugger and fill the output table with corresponding
value of register and give the reason if the value of flag is set to 1.

Program 1: [Assume registers are set to default values]

Mov ah,07Fh
Output:
Mov ax,1234

Mov bh,al AX =
AX =
Mov bl,ah BX =
BX=

Program 2: [Assume registers are set to default values]

Mov al,81 Output:


Add al,0FEh
AX =
AX =
FLAG BITS :

Program 3: [Assume registers are set to default values]

Mov ax,5510
Sub al,2

Output:

AX =
AX =
FLAG BITS :

UMT, Lahore Page 5


CS Department Computer Organization && Assembly language

Program 4: [Assume registers are set to default values]

Mov ah,10
Output:
Mov bh,10
Sub ah,bh AX =
BX=
FLAG BITS :

Program 5: [Assume registers are set to default values]

Mov ax,0FFFEh
Output:
Sub al,2
Mov bx,02D8Ch AX =
Add bx,ax AX =
FLAG BITS :
BX=
BX=
FLAG BITS :

Program 6: [Assume registers are set to default values]

Mov al,100
Add al,50
Output:

AL=
FLAG BITS :

UMT, Lahore Page 6


CS Department Computer Organization && Assembly language

Program 7: [Assume registers are set to default values]

Mov ax,32760
Output:
Add ax, 50
AX=
AX=
FLAG BITS :

Program 8: [Assume registers are set to default values]

Mov ax,65530
Output:
Add ax, 80
AX=
AX=
FLAG BITS :

UMT, Lahore Page 7

You might also like