سيطره 8

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

8086 Microprocessor

Lecture 8

8086 Microprocessor
Instruction Set

4. branch Instructions
Mnemonics: Unconditional jump & conditional jump
There are two types of branches or jumps namely conditional and
unconditional branches.
‫تعليمات القفز‬
‫ و هناك نوعان من‬.‫الغاية من تعليمة القفز هي تعديل طريق تنفيذ التعليمات في البرنامج‬
‫ في القفز غير المشروط ال يوجد‬.‫ القفز المشروط و القفز غير المشروط‬: ‫ وهي‬،‫تعليمات القفز‬
‫أي شروط من أجل حدوث القفز أما في القفز المشروط فإن الحاالت الشرطية الموجودة في‬
‫ ففي حال تحقق الحاالت‬،‫لحظة تنفيذ تعليمة القفز تتخذ القرار فيما إذا سيحدث القفز أم ال‬
.‫ و إال ُيتابع التنفيذ بالتعليمة التي تلي تعليمة القفز في البرنامج‬،‫الشرطية فإنه يتم القفز‬

Unconditional jump
This is performed by the JMP instruction. Unconditional execution often
involves a transfer of control to the address of an instruction that does not
1
follow the currently executing instruction. Transfer of control may be forward
to execute a new set of instructions, or backward to re-execute the same
steps.
Conditional jump
This is performed by a set of jump instructions j<condition> depending upon
2
the condition. The conditional instructions transfer the control by breaking the
2
sequential flow and they do it by changing the offset value in IP.
8086 Microprocessor
Instruction Set

4. branch Instructions
Mnemonics: Unconditional jump & conditional jump
Unconditional jump

The JMP instruction provides a label name where the flow of control is transferred
immediately. The basic syntax of JMP instruction:
JMP label
To declare a label in your program, just type its name and add ":" to the
end, label can be any character combination but it cannot start with a
number, for example here are 3 legal label definitions:
label1:
label2:
a:
Label can be declared on a separate line or before any other instruction, for
example:
x1:MOV AX, 1
3
x2: MOV AX, 2
8086 Microprocessor
Instruction Set

4. branch Instructions
Mnemonics: Unconditional jump & conditional jump
Unconditional jump

The JMP instruction provides a label name where the flow of control is transferred
immediately.
EXAMPLE
MOV AX, 00 ; Initializing AX to 0
MOV BX, 00 ; Initializing BX to 0
MOV CX, 01 ; Initializing CX to 1
L1:
ADD AX, 01 ; Increment AX
ADD BX, AX ; Add AX to BX
SHL CX, 1 ; shift left CX, this in turn doubles the CX value
JMP L1 ; repeats the statements
4
8086 Microprocessor
Instruction Set

4. branch Instructions
Mnemonics: Unconditional jump & conditional jump
Unconditional jump

Example
org 100h
mov ax, 5 ; set ax to 5.
mov bx, 2 ; set bx to 2.

jmp calc ; go to 'calc'.

back: jmp stop ; go to 'stop'.

calc:
add ax, bx ; add bx to ax.
jmp back ; go 'back'.

stop:
ret ; return to operating system.
5

8086 Microprocessor
Instruction Set

4. branch Instructions
Mnemonics: Unconditional jump & conditional jump
Conditional jump

• If some specified condition is satisfied in conditional jump, the control flow is


transferred to a target instruction.

• There are numerous conditional jump instructions, depending upon the condition
and data.
• The flag conditions are checked depending upon the instruction, if
they are true the program control is transferred to the memory
address pointed by the IP register. If the condition is not satisfied,
then the program continues in a sequential manner.

6
8086 Microprocessor
Instruction Set
Table below shows the mnemonics of all the conditional branches instructions.
Instructions Operation Testing Condition

JA/JNBE Jump if Above/Not Below or Equal C=0 and Z=0


JAE/JNB/JNC Jump if Above or Equal/ Jump if Not Below/Jump if No Carry C=0
JB/JNAE Jump if Below/ Jump if Not Above or Equal C=1
JBE/JNA Jump if Below or Equal/ Jump if Not Above (C or Z) =1
JC Jump if Carry C=1
JNC Jump if Not Carry C=0
JCXZ Jump if the CX register=0 CX=0
JE/JZ Jump if Equal/Jump if Zero Z=1
JG/JNLE Jump if Greater/Jump if Not Less Than or Equal ((S xor O) or Z) = 0

JGE/JNL Jump if Greater or Equal/Jump if Not Less Than (S xor O)=0


JL/JNGE Jump if Less Than/Jump if Not Greater Than or Equal (S xor O)=1

JLE/JNG Jump if Less than or Equal/Jump if Not Greater ((S xor O) or Z) = 1

JNE/JNZ Jump if Not Equal/ Jump if Not Zero Z=0


JNP/JPO Jump if Not Parity/Jump if Parity Odd P=0
JNS Jump if Not Signed/Jump if Positive S=0
JO Jump if Overflow O=1
JNO Jump if Not Overflow O=0
JP/JPE Jump if Parity/ Jump if Parity Even P=1
7
JS Jump if Signed/ Jump if Negative S=1

8086 Microprocessor
Instruction Set

:‫تعليمات القفز المشروط مشروحة في الجدول التالي‬


‫الكلمة المختزلة‬ ‫المعنى‬
JC CF = 1 ‫إذا كان‬ ‫القفز‬
JNC CF = 0 ‫إذا كان‬ ‫القفز‬
JO OF = 1 ‫إذا كان‬ ‫القفز‬
JNO OF = 0 ‫إذا كان‬ ‫القفز‬
JS SF = 1 ‫إذا كان‬ ‫القفز‬
JNS SF = 0 ‫إذا كان‬ ‫القفز‬
JCXZ CX = 0000 ‫إذا كان‬ ‫القفز‬
JE/JZ ‫أو إذا كان الناتج يساوي الصفر‬/‫في حالة التساوي‬ ‫القفز‬
JGE/JNL ‫القفز إذا لم يكن أصغر‬/‫إذا كان أكبر أو يساوي‬ ‫القفز‬
JA/JNBE ‫القفز إذا لم يكن تحت أو يساوي‬/‫إذا كان فوق‬ ‫القفز‬
JAE/JNB ‫القفز إذا لم يكن تحت‬/‫إذا كان فوق أو يساوي‬ ‫القفز‬
JB/JNAE ‫القفز إذا لم يكن فوق أو يساوي‬/‫إذا كان تحت‬ ‫القفز‬
JBE/JNA ‫القفز إذا لم يكن فوق‬/‫إذا كان تحت أو يساوي‬ ‫القفز‬
JG/JNLE ‫القفز إذا لم يكن أصغر أو يساوي‬/‫إذا كان أكبر‬ ‫القفز‬
JLE/JNG ‫القفز إذا لم يكن أكبر‬/‫إذا كان أصغر أو يساوي‬ ‫القفز‬
JNE/JNZ ‫القفز إذا كان الناتج يساوي قيمة غير صفرية‬/‫إذا لم يكن يساوي‬ ‫القفز‬
JNB/JBO PF = 0 ‫القفز إذا كان‬/‫ غير موجودة‬Parity ‫إذا كانت خانة‬ ‫القفز‬
JP/JPE PF = 1 ‫القفز إذا كان‬/Parity ‫في حالة وجود خانة‬ ‫القفز‬
8
8086 Microprocessor
Instruction Set
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.
ORG 100h L1:
.MODEL SMALL MOV DX,OFFSET MSG
.DATA MOV AH,09H
NUM_1 DB 23H INT 21H
NUM_2 DB 93H RET
MSG DB "Equal Numbers$"
MSG1 DB "Num_1 is less than Num_2$" L2:
MSG2 DB "Num_1 is greater than Num_2$" MOV DX,OFFSET MSG1
MOV AH,09H
.CODE INT 21H
MOV AX, @DATA RET
MOV DS, AX
L3:
MOV AH,NUM_1 MOV DX,OFFSET MSG2
MOV CH,NUM_2 MOV AH,09H
CMP AH,CH INT 21H
JE L1 ;If AH and CH are equal RET
JB L2 ;If AH is less than CH
JA L3 ;If AH is greater than CH

8086 Microprocessor
Instruction Set

5. Loop Instructions
Mnemonics: Loop instructions

The JMP instruction can be used for implementing loops.

For example:-
The following code snippet can be used for executing the loop-body 10 times.

MOV CL, 10
L1:
<LOOP-BODY>
DEC CL
JNZ L1
The basic LOOP instruction has the following syntax:
LOOP label
The above code snippet could be written as:
MOV CX,10
L1:
< LOOP-BODY>
Loop L1
10
8086 Microprocessor
Instruction Set

5. Loop Instructions
Mnemonics: Loop instructions
‫تعليمات الحلقات‬
‫ و هذه التعليمات يمكن‬.‫هناك ثالث تعليمات مصممة بشكل خاص لتحقيق عملية الحلقة‬
:‫ و هي مبينة في الجدول التالي‬.‫استعمالها بدال ً من تعليمات القفز الشرطي‬

The various LOOP instructions and their functions are listed below.

Mnemonic Meaning Format Operation

LOOP short- Decrements CX by one, if CX ≠


LOOP Loop
label 0, jump to "short-label".

loop while Decrements CX by one, if CX ≠ 0


LOOPE/LOOPZ
LOOPE/LOOPZ equal/Loop and ZF = 1, jump to "short-
short-label
while zero label".
loop while
Decrements CX by one, if CX ≠ 0
not equal LOOPNE/LOOP
LOOPNE/LOOPNZ and ZF = 0, jump to "short-
/Loop while NZ short-lablel
label".
not zero
11

8086 Microprocessor
Instruction Set

5. Loop Instructions
Mnemonics: Loop instructions
Example
By 8086 assembly language write ten stares (*), using loop instruction.

ORG 100h

mov cx,50
label1:
mov ah,02h ; Dos function 02h to Write character
mov dl,'*' ; character to write
int 21h ; dos interrupt 21h
loop label1

RET

12
8086 Microprocessor
Instruction Set

5. Loop Instructions
Mnemonics: Loop instructions
Example
By 8086 assembly language write the English letters A-Z, using loop instruction.
ORG 100h

;PROGRAM TO PRINT A TO Z

MOV CX,26
MOV DX,65

L1:
MOV AH,2
INT 21H
INC DX
LOOP L1

RET

13

You might also like