FM Exp 7
FM Exp 7
Experiment-7
AIM: Toperform Branch Operations.
THEORY:
There are two types of branches or jumps namely
branches. conditional and unconditional
Opcode LABEL
It is a 2-byte instruction consisting of
1-Byte Opcode and 1-byte Label. Label value is
between 00 and FF. It is sign-extended to 16-bits and added to the contents of IP
register. The target address must be within the -128
conditions are checked depending upon the instruction,toif +127
they
bytes of IP, The flag
are
control is transferred to the menory address pointed by the lP true the program
is not satisfied, then the program register. If the condition
continues in a sequential manner.
List of 8086 Conditional Branch
Instructions
Table below shows the mnemonics' of all the
conditional branches instructions.
InstructionsOperation
JA/NBE Jump if Above/Not Below or Equal Testing Condition
Jump if C=0 andZ=0
|JAE/JNB/JNC|Carry Above or Equal/ Jump if Not Below/jump if No C=0
UB/JNAE Jump if Below/ Jump if Not Above or Equal
C=1
MMorwodi MarwadiI University
nivctsiy
Department of Computer Engineering
Subject: Fundamental of
Processors (01CEO509) Aim:To perform Branch Operations.
Experiment No: 07 Date: Enrolment No: 92200103297
These instructions are executed after some other instructions which affects the content
of flag registers. Let's discuss these instructions in detail through examples.
8086 Microprocessor Assembly Comparison Example
The code below compares two numbers and print if number 1 is equal, greater or less
than number 2. This code is implemented using three conditional branches which are
JE, JB and JA.
Assembly Code
JA/JNBE wllcheck the CF and ZF lags. If both are 0, then the IP willjump to the target
address. Also, if both CF and ZF are equal to 1, then the program will continue to execute
sequentially. Moreover, if any one of them is 0 and other is 1, then this instruction will
have no effect of program execution.
Code:
MMarwadi NAAC Marwadi University
Universit A
Department of Computer Engineering
-DATk
NuM-4 DB .23H
"
MS8 DB' Egunl humters
.coDE
MoVA, 094
(NT 24
RET
Morwadi NAAC Marwadi University
Iaierstty
Department of Computer Engineering
instruction after JAE instruction, Now replace ADD instruction with CMP instruction. If
AH is greater or equal to CH data, then the program counter will jump to the L1label.
Code:
RET
MoDEL SNAU
-CODE
Mov AH, VAR_4
CMP AH AL
SAE
Output
AF
ashe
Marwadi AC
Tnietsity MarwadiUniversity
Department of Computer Engineering
Subject: Fundamental of
Processors (01CE0509) Aim:To perform Branch Operations.
Experiment No: 07 Date: Enrolment No: 92200103297
8086 J0 Branch
Instruction:
The code below explains the
behavior of J0
the overflow. If the result is too large to fit instruction. It adds two numbers and
overflow bit to 1. The JO instruction checks the destination register, then it willcheck
in the
transferred to NEXT label which will then display overflow flag. If it is 1,the control willset
emulator screen. If the OF=0, then the sum is message of "0VERFLOW" on thebe
stored in memory. stored in the variable "RESULT" which is
In this example, the two
numbers are 0C9H and 95H. Adding these two
15E resulting into overflow.
after labelNEXT are As OF = 1, therefore after JO numbers give
executed. instruction, the instructions
Code:
) 92oo1032 /by Bnno NgIKU MANA:
MSG DB "OVBRFLow
NUM-a DB -CO
NuMe DB 9SH
"CoDE
ou tx DATh
Mov Ds, Ay.
ADD A4,C.
MoV BLAA
RT
NaxT. .Mov x, opFSSET ss
MOV tt, 09
Marwadi NAAC
Marwadi University
LniCsIty
Menwedi Cha voa a Gop
Departmentof Computer Engineering
Subject: Fundamental of
Processors (01CE0509) Aim:To perform Branch Operations.
Experiment No: 07 Date: Enrolment No: 92200103297
8086 JNP Branch
Instruction:
The JNP instruction checks the parity flag. If
parity is odd or PF=0, the
instruction checks if parity isprogram
will jump to the label address. The JP counter
Code even or PF=1.
j220o|3
Nom-A PB .0c94
NJM_ 2 DB 9St
CoDE
Mor D5, 4x
Mov At, NUM4
JP NEXT
Mov At, h
WT 2H.
Mov AH, 0t
PEr
MMorwodi! MAaC Marwadi University
B|\ersii o
Me wad Cheda
Department of Computer Engineering
Subject: Fundamental of
Processors (01CE0509) Aim:To perform Branch Operations.
Experiment No: 07 Date: Enrolment No: 92200103297
Output
D
ep tacençle Ves
FA0B:8 FA00:0N
TNT 921h
NU
HU1 DP 0C?M
NECJLT DB 01 DUPC7)
DATA
4111
Assembly Code
CRE lo0
- DATA
.CoDE
NAAC
NMorwadi Marwadi University
lniersity
Mewe Chee a G
|Department of Computer Engineering
Subject: Fundamental of
Processors (01CE0S509) Aim:Toperform Branch Operations.
Experiment No: 07 Date: Enrolment No: 92200103297
The code in example 5 adds two numbers and check if the result is a positive number or
not. If the number is positive, the program stops running otherwise the program wil
jump to the NEXT label in which the result is multiplied with -1 to convert it into a
positive number. Output
O emulator Exp?Sruno_IS.com. X
file math debug view external virtual devices virtual drive help
X 00 95 HDD LB+
82112: Ct 193 1 ORG
109)
ADD [B8 + MODEL SMALL
DX 00 o0 H7113: 78 12 ADD (BX . DAIA
07 00
37E18: S3 173 ADD (BX .coDE
611A XES MOU AX, eDATA
a2118: F6 246 s
790 87119: EB 227 AD + SIJ, AL MOr A8,NUM
SF FFFE 3 195 + SI), 1GU CXNUM_
B?11C: 90 144 ADD CB SLI . JS NET
BF 0000 a 141 RET
PE
ADD TBX
ADD [B8 S I J . AL
NEXI : A
1H
A7?: 90 : 4 ADD [BX
ADD BX
SI}, AL
SI). AL
AUL BL
07 90
DE
ES 07 00 screen sOurce reset aus vars debua slack
analvse
Conclusion: Tm h