Você está na página 1de 4

MICROPROCESSOR PROGRAMMING Date __________________________

GCU,LAHORE ROLL NO. _______________________

Experiment No. 2
Effect of arithmetic and logical operations on status Register
Objective
In this lab students will be able to learn:

• How status register is affected by arithmetic and logical instructions


• Overflow in signed and unsigned numbers.

Introduction:
One important feature that distinguishes a computer from other machines is the computer’s ability to make
decisions. The circuits in the CPU can perform simple decision making based on the current state of the
processor. For the 8086 processor, the processor state is implemented as nine individual bits called Flags.
Each decision made by the 8086 is based on the values of these flags. The flags are placed in the Flags
register and they are classified as either status flags or control flags. These flags reflect the status of
computation.

Flags Register:
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 two bits have no significance.

The status flags:


The processor uses the status flags to reflect the result of an operation. For example, if SUB AX, AX is
executed, the zero flag becomes 1, thereby indicating that a zero result was produced.

• Carry Flag (CF)

CF=1 if there is a carry out from the most significant bit (msb) on addition, or there is a borrow into the
msb on subtraction; otherwise, it is 0. 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
parity. For example, if the result of a word addition is FFFEH, then the low byte contains 7 on bits, so PF=0.

Flag names and Symbols


MICROPROCESSOR PROGRAMMING Date __________________________
GCU,LAHORE ROLL NO. _______________________

Status Flags

Bit Name Symbol


0 Carry flag CF
2 Parity flag PF
4 Auxiliary carry flag AF
6 Zero flag ZF
7 Sign flag SF
11 Overflow flag OF
Control Flags

Bit Name Symbol


8 Trap flag TF
9 Interrupt flag IF
10 Direction flag DF
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.

Zero Flag (ZF)

ZF=1 for a zero result, and ZF=0 for a nonzero result.

Sign Flag (SF)

SF=1 if the msb of a result is 1; it means the result is negative if you are giving a signed interpretation.
SF=0 if the msb is 0.

Overflow Flag (OF)


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

The phenomenon of overflow is associated with the fact that the range of numbers that can be represented
in a computer is limited. Two types of overflows are signed and unsigned overflows. They are independent
phenomena. When we perform an arithmetic operation such as addition, there are four possible outcomes:
(1) no overflow, (2) signed overflow only, (3) unsigned overflow only, and (4) both signed and unsigned
overflows. OF=1 for signed overflow and CF=1 for unsigned overflow.

Unsigned Overflow

On addition, unsigned overflow occurs when there is a carry out of the msb. This means that the correct
answer is larger than the biggest unsigned number; that is, FFFFh for a word and FFh for a byte. On
subtraction, unsigned overflow occurs when there is a borrow into msb. This means that the correct answer
is smaller than 0.

Signed Overflow
MICROPROCESSOR PROGRAMMING Date __________________________
GCU,LAHORE ROLL NO. _______________________

On addition of numbers with the same sign, signed overflow occurs when the sum has a different sign.
Subtraction of numbers with different signs is like adding numbers of the same sign. For example, A-(-
B)=A+B and –A-(+B)=-A-B,. Signed overflow occurs if the result has a different sign than expected.

Exercise
1-AF is used for what? [2]

_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

2-For each of the following instructions, give the new destination contents and the new settings of
CF, SF, PF,ZF, and OF. Suppose that the flags are initially 0 in each part. [5]

Instruction Registers Contents CF SF ZF PF OF


ADD AX,BX AX=7FFFH, BX=0001H
SUB AL,BL AL=01H, BL=FFH
DEC AL AL=00H
NEG AL AL=7FH
XCHG AX,BX AX=1ABCH, BX=712AH
ADD AL,BL AL=80H, BL=FFH
SUB AX,BX AX=0000H, BX=8000H
NEG AX AX=0001H

3- Suppose that AX and BX both contain positive numbers, and ADD AX,BX is executed. Show that
there is a carry into the msb but no carry out of the msb iff signed overflow occurs. [3]

_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

4-Suppose that AX and BX both contain negative numbers, and ADD AX, BX is executed. Show
that there is a carry out of msb but no carry into the msb iff signed overflow occurs. [3]

_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
MICROPROCESSOR PROGRAMMING Date __________________________
GCU,LAHORE ROLL NO. _______________________

5-Suppose that ADD AX,BX is executed. In each of the following parts, the first number being added
is the contents of AX and the second number is the contents of BX. Give the resulting value of AX
and tell whether the signed or unsigned overflow occurred? [6]

E1E4h 7132h 6389H


+1ACBh +7000h +1176H
Solution:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

Você também pode gostar