Академический Документы
Профессиональный Документы
Культура Документы
Object:
.Using instructions for Unconditional and conditional branch
Theory:
Controlling the program flow is a very important thing, this is where your
program can make decisions according to certain conditions.
• Unconditional Jumps
The basic instruction that transfers control to another point in the program
is JMP.
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:
x1:MOV AX, 1
x2: MOV AX, 2
• Conditional Jumps
1
•
Jump instructions that test single flag
JNC , JNB, JAE Jump if Not Carry (Not Below, Above Equal). CF = 0
As you can see there are some instructions that do that same thing, that's correct,
they even are assembled into the same machine code, so it's good to remember
that when you compile JE instruction you will get it disassembled as:JZ
Different names are used to make programs easier to understand and code
Condition
Instruction Description
2
Instruction Description Condition
CF = 0
Jump if Above (>).
JA and
Jump if Not Below or Equal (not <=).
ZF = 0
CF = 1
Jump if Below or Equal (<=).
JBE , JNA or
Jump if Not Above (not >).
ZF = 1
Example:-
3
1. Write 8086 program that compares the element of AL with the element of
BL.if the two element are found to be equal save [FF] in memory location with
offset address RESULT otherwise save [00] into this location.
include emu8086.inc
ORG 100h
MOV RESULT,00
JMP stop ; jump to stop.
stop:
HLT
RESULT Db 33
• Try the above example with different numbers for AL and BL,
open flags by clicking on [FLAGS] button, use [Single Step] and see
what happens, don't forget to recompile and reload after every change
(use F5 shortcut).
• All conditional jumps have one big limitation, unlike JMP instruction they
can only jump 127 bytes forward and 128 bytes backward (note that most
instructions are assembled into 3 or more bytes).
4
Here is an example2:
include emu8086.inc
ORG 100h
MOV RESULT,00
JMP stop ; jump to stop.
HLT
RESULT Db 33
END
5
Procedures:-
For each of the following exercises:
1-Write down the following program in the text editor and make # COM file.
2-Compile & emulate the program to its Hex code.
3-Compare between the assembled and disassembled programs.
4-Write down the machine instructions (Hex code) of the program
5-Use the single step execution command to run the program.
6-Verify the contents of the registers used in each instruction used in this
program including the IP in each step of the execution.
Exercises:
2- Find the largest element in the ARRAY of data contains 10 bytes unsigned
numbered. Store the maximum in the data segment memory location MAX
[ARRAY]= [5, 67, 70, 15, 12, E3, 77, 14, 8, 6]
3- Find the smallest element in the RECORD A store the minimum in the
memory location with offset address FOUND.
[RECORD A]= [FI, 1A, 28, 30, 4B, 89]