Uploaded by Guru Balan

Branching Instructions

advertisement
Jump Instructions in 8086 Microprocessor
Jump Instructions are used for changing the flow of execution of instructions in the processor.
If we want jump to any instruction in between the code, then this can be achieved by these
instructions. There are two types of Jump instructions:
1. Unconditional Jump Instructions
2. Conditional Jump Instructions
1) Unconditional Jump Instructions
These instructions are used to jump on a particular location unconditionally, i.e. there is no need
to satisfy any condition for the jump to take place. There are three types of procedures used for
unconditional jump. They are:
i.
ii.
NEAR – This procedure targets within the same code segment. (Intra-segment)
FAR - In this procedure, the target is outside the segment and the size of the pointer is
double word. (Inter-segment)
Syntax:
JMP procedure_namememory_location
Example: JMP short target
2) Conditional Jumps
In these types of instructions, the processor must check for the particular condition. If it is true,
then only the jump takes place else the normal flow in the execution of the statements is
maintained.
The ALU operations set flags in the status word (Flag register). The conditional jump statements
tests the flag and jump is the flag is set.
There are following types of conditional jump instructions:
i) JC : Stands for 'Jump if Carry'
It checks whether the carry flag is set or not. If yes, then jump takes place, that is: If CF = 1,
then jump.
ii) JNC : Stands for 'Jump if Not Carry'
It checks whether the carry flag is reset or not. If yes, then jump takes place, that is: If CF = 0,
then jump.
iii) JE / JZ : Stands for 'Jump if Equal' or 'Jump if Zero'
It checks whether the zero flag is set or not. If yes, then jump takes place, that is: If ZF = 1, then
jump.
iv) JNE / JNZ : Stands for 'Jump if Not Equal' or 'Jump if Not Zero'
It checks whether the zero flag is reset or not. If yes, then jump takes place, that is: If ZF = 0,
then jump.
v) JP / JPE : Stands for 'Jump if Parity' or 'Jump if Even Parity'
It checks whether the Parity flag is set or not. If yes, then jump takes place, that is: If PF = 1,
then jump.
vi) JNP / JPO : Stands for 'Jump if Not Parity' or 'Jump if Odd Parity'
It checks whether the Parity flag is reset or not. If yes, then jump takes place, that is: If PF = 0,
then jump.
The CALL instruction in the 8086 microprocessor
The CALL instruction is used whenever we need to make a call to some procedure or a
subprogram. Whenever a CALL is made, the following process takes place inside the
microprocessor:




The address of the next instruction that exists in the caller program (after the program
CALL instruction) is stored in the stack.
The instruction queue is emptied for accommodating the instructions of the procedure.
Then, the contents of the instruction pointer (IP) is changed with the address of the first
instruction of the procedure.
The subsequent instructions of the procedure are stored in the instruction queue for
execution.
The Syntax for the CALL instruction is as follows:
CALL subprogram_name
The RET instruction in the 8086 microprocessor
The RET instruction stands for return. This instruction is used at the end of the procedures or
the subprograms. This instruction transfers the execution to the caller program. Whenever the
RET instruction is called, the following process takes place inside the microprocessor:

The address of the next instruction in the mainline program which was previously stored
inside the stack is now again fetched and is placed inside the instruction pointer (IP).

The instruction queue will now again be filled with the subsequent instructions of the
mainline program.
The Syntax for the RET instruction is as follows:
RET
The following diagram illustrates how the control of the instruction execution is transferred
within the code from one program to another whenever a procedure is called and whenever it
returns the execution. In most of the cases, the procedure CALL is made from the mainline
program and hence the control is returned to the mainline program itself.
Note: The storing and fetching of the address inside and from the stack takes place in the same
way as the data is pushed into it or popped form it.
LOOP InstructionThis instruction is used to repeat a series of instruction some number of times
Example:
MOVBX, OFFSET PRICE ;Point BX at first element in array
MOVCX, 40;Load CX with number of ;elements in array
NEXT: MOVAL, [BX]; Get elements from array
ADD AL, 07H;Ad correction factor
DAA; decimal adjust result
MOV[BX], AL; Put result back in array
LOOP NEXT; Repeat until all elements ;adjusted.
LOOPE / LOOPZ InstructionThis instruction is used to repeat a group of instruction some number of times until CX =0 and
ZF = 0
Example:
MOVBX, OFFSET ARRAY ;point BX at start of the array
DEC BX MOVCX, 100;put number of array elements in ;
CX NEXT:IN CBX ;point to next element in array
CMP[BX], 0FFH;Compare array elements FFH
LOOP NEXT
LOOPNE/LOOPNZInstructionThis instruction is used to repeat a group of instruction some number of times until CX =0 and
ZF = 1
Example:
MOVBX, OFFSET ARRAY1 ;point BX at start of the array
DEC BX
MOVCX, 100;put number of array elements in ;CX
NEXT:INC BX;point to next elements in array
CMP[BX], 0FFH;Compare array elements 0DH
LOOPNE NEXT
Download