0% found this document useful (0 votes)
20 views14 pages

Simple Programs - PA23PH008

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views14 pages

Simple Programs - PA23PH008

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

SIMPLE PROGRAMS INVOLVING BRANCH,

LOGICAL INSTRUCTIONS AND SORTING

Presented by
B.Sugapriya
II M.Sc physics
BRANCHING INSTRUCTIONS

8086 Types of branch Instructions

There are two types of branches or jumps namely conditional and

unconditional branches.

Unconditional Branch Instructions

The unconditional branches are those in which the program

counter jumps to the label address provided within the

instructions.
CONDITIONAL BRANCHING

The conditional branches are those instructions whose execution is


based on some condition. It checks one or more flag conditions and
transfers the control to a new memory location.
BRANCHING INSTRUCTIONS
8086 Check Carry Flag Assembly Example
The JAE/JNB/JNC instructions check Carry flag (CF). If it
is 0, jump to the target address.
Example
MOV AH,0C9H
MOV AL,7AH
ADD AH,CH
JNC
ADD AH,AL
RET
8086 JO Branch Instruction
The JO instruction checks the overflow flag. If it is 1, the
control will be transferred to NEXT label which will then
display message of “OVERFLOW” on the emulator screen. If
the OF=0, then the sum is stored in the variable “RESULT”
which is stored in memory.
Example:
MOV AH,23H
MOV CH,93H
ADD AH,CH
JO NEXT
MOV BL,AH
RET
8086 Logical Instructions

AND Instruction
The AND instruction perform logical AND operation between
two operands. The source can be an immediate, register, or a
memory location and the destination can be either a register or
a memory location. Both source and destination operands
cannot be a memory location.
Example:
MOV BX,3527
MOV CX,2968
AND BX,CX
RET
OR Logical Instruction

It performs the OR operation between two operands and


stores the result back into the destination operand. The
destination operand can be a register or a memory
location whereas the source can be immediate, register, or
a memory location. But Keep in mind, both operands
should not be a memory location.
Example:
MOV AX, 3527
MOV CX, 2968
OR AX,CX
RET
XOR Instruction
This instruction performs the XOR operation between
bits of source and destination operands. The source
operand can be either a register or memory address
whereas destination operand can be immediate,
register or memory location.
Example:
MOV AX,98H
MOV BX,9CH
XOR AX,BX
RET
CMP Compare Instruction of 8086
The compare instruction (CMP) compares the data of the two
operands and depending upon the result sets the flags. The
destination operand remains unchanged. It compares the two
operands by computing the difference of two operands and
sets CF, ZF and SF flags. The CMP cannot directly compare
the data of two memory addresses.
Example:
MOV AX,25H
MOV BX,A5H
CMP AX,BX
RET
Sorting an array in ascending order
Program
MOV SI,1100H
MOV CH,[SI]
DEC CH
INC SI
MOV AL,[SI]
INC SI
CMP AL,[SI]
JC
XCHG AL,[SI]
XCHG AL,[SI – 1]
DEC CH
JNZ REPEAT
HLT
SI DATA
1100H 05
1101H AA
1102H 77
1103H FF
1104H 1E
1105H 2F
MOV SI,1100H
MOV CH,[SI]
DEC CH
INC SI
MOV AL,[SI]
INC SI
CMP AL,[SI]
JNC
XCHG AL,[SI]
XCHG AL,[SI - 1]
DEC CH
JNZ REPEAT
HLT
SI DATA
1100H 05
1101H 1F
1102H 0A
1103H 1C
1104H 08
1105H 2D
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy