Sie sind auf Seite 1von 23

Microprocessors

Lecture 8
Program Control Instructions

Eng. Anis Nazer


First Semester 2015-2016
Contents
Jump instructions:
Unconditional jumps (JMP)
short jump
near jump

far jump

Indirect jumps

Conditional jumps
Loop instructions
Instruction pointer
Instruction pointer holds the offset of next instruction to be executed
next instruction is located at CS:IP
Example: Consider the following instructions, and assume that IP =
0005, what is the value of IP after executing each instructions
Assembly MachineLanguage
MOVAL,7 B007
MOVBX,0F3h BBF300
CBW 98
IMULBX F7EB
MOV[SI],AX 8904
MOV[SI+2],DX 895402
Instruction pointer
Memory view of the previous
example:

Assembly MachineLanguage
MOVAL,7 B007
MOVBX,0F3h BBF300
CBW 98
IMULBX F7EB
MOV[SI],AX 8904
MOV[SI+2],DX 895402
Jump instructions

JMP changes the contents of the IP register


this will cause the processor to execute a different
instruction than the one written after the jump instruction
Short jump:
adds a one byte signed displacement to the value of IP
jumps to a location within -128 to 127 bytes of the
current instruction
Jump instructions

Near jump:
Add a 2 byte signed displacement to the value of IP
jumps to a location within -32768 to 32767 bytes of the
current instruction
Far jump:
jumps to any location in the memory
it modifies the value of CS and IP
Jump instructions
Jump instructions
Short jump

EB
Jump instructions
Near jump

0003H

E9
Jump instructions
Far jump

EA
JMP instruction

A displacement is specified in the instruction


It is not practical for the programmer to calculate the value
of the displacement
This hard task is performed by the assembler by using a
label
A label is used to refer to a location in a symbolic way
Label is a word written before the instruction
it should end with a semi colon
Jump instructions
Example:
start:MOVAL,BL
ADDAL,AL
JMPstart
startis a label
the assembler calculates the correct value to be added/subtracted in
the JMP instruction
In our example the displacement is . ?
The assembler should make the correct choice between the short,
near, or far jumps
Indirect Jump

The operand of the jump can be a 16 bit register.


The value of the register is transferred to IP
Example:
MOV AX, 123h
JMP AX
here, the new value of IP is 123h
Double indirect jump

The operand of the jump instruction can be a memory


location
The value stored in the memory location is transferred to
IP
Example
MOV SI, 123h
JMP [SI]
here the 16 bit value in location DS:SI is transferred to IP
Jump instructions

The following directives can be used to specify the jump


type
SHORT to specify a short jump
Ex. JMP SHORT start
NEAR PTR to specify a near jump
Ex. JMP NEAR PTR start
FAR PTR to specify a far jump
Ex. JMP FAR PTR [DI]
this will transfer 32 bits : 16 bits to IP, 16 bits to CS
Conditional Jumps

In 8086 the conditional jumps are always short jumps


The conditional jumps test the FLAGS to determine
whether to jump or not
if the condition is correct, the jump is performed, otherwise
the instruction written after the jump is executed
conditional jumps usually are written after a CMP or TEST
instructions
Conditional Jumps
Conditional jumps

Conditional jumps continued....


Conditional Jumps

For signed numbers use


JG, JL, JGE, JLE, JE, JNE
For unsigned numbers use
JA, JB, JAE, JBE, JE, JNE
Examples:
Write instructions that will jump if the value of AX is less
than 15
Write instructions that will jump if the third bit of DX is 0
Write instructions that will jump if the third bit of DX is 1
Loop instruction

LOOP instruction decrements CX, if CX does not equal


zero, it executes the jump
Here CX is treated as a 16 bit unsigned number
Example: what is the value of AX after executing the
instructions:

MOVAX,0
MOVCX,5
next:ADDAX,7
LOOPnext
Loop instruction

Example: Write instructions that will add the numbers from


3 to 14
Conditional Jump instructions

Example: Assume AX = 1, write instructions that will keep


doubling AX until AX is larger that 10000
Conditional Jumps

Example: What does the following code do ?


gradesDW88,92,65,70,50,47
LEADI,grades
MOVCX,0
MOVAX,0
next:ADDAX,[DI]
ADDDI,2
INCCX,
CMPCX,5
JNAnext
MOVDL,6
DIVDL

Das könnte Ihnen auch gefallen