Program Execution Transfer Instructions in 8086 Microprocessor:
The Program Execution Transfer Instructions in 8086 Microprocessor are namely
a) Unconditional transfer instructions:
- CALL
- RET
- JMP
- J cond
CALL Instruction :
The CALL instruction is used to Program Execution Transfer Instructions in 8086 Microprocessor to a subprogram or procedure. There are two basic types of CALLs, near and far. A near CALL is a call to a procedure which is in the same code segment as the CALL instruction. When the 8086 executes a near CALL instruction it decrements the stack pointer by two and copies the offset of the next instruction after the CALL on the stack. It loads IP with the offset of the first instruction of the procedure in same segment. The near CALL is also known as intrasegment CALL
A far CALL is a call to a procedure which is in a different segment from that which contains the CALL instruction. When the 8086 executes a far CALL it decrements the stack pointer by two and copies the contents of the CS register to the stack. It then decrements the stack pointer by two again and copies the offset of the instruction ,after the CALL to the stack. Finally, it loads CS with the segment base of the segment which contains the procedure and IP with the offset of the first instruction of the procedure in that segment. The far CALL is also known as inter segment CALL.
RET Instruction :
The RET instruction will return Program Execution Transfer Instructions in 8086 Microprocessor from a procedure to the next instruction after. the CALL instruction in the calling program. If the procedure is a near procedure (in the same code segment as the CALL instruction), then the return will be done by replacing the instruction pointer with a word from the top of the stack.
If the procedure is a far procedure (in a different code segment from the CALL instruction which calls it), then the instruction pointer will be replaced by the word at the top of the stack. The stack pointer will then be incremented by two. The code segment register is then replaced with a word from the new top of the stack. After the code segment word is popped off the stack, the stack pointer is again incremented by two. These words/word are the offset of the next instruction after the CALL. So 8086 will fetch the next instruction after the CALL.
A RET instruction can be followed by a number, for example, RET 4. In this case the stack pointer will be incremented by an additional four addresses after the IP or the IP and CS are popped off the stack. This form is used to increment the stack pointer up over parameters passed to the procedure on the stack.
Flags : The RET instruction affects no flags.
JMP Instruction :
This instruction will always cause the Program Execution Transfer Instructions in 8086 Microprocessor to fetch its next instruction from the location specified in the instruction rather than from the next location after the JMP instruction.
There are two basic types of JMPs, near and far. A near JMP is a jump where destination location is in the same code segment. In this case only IP is changed. A near JMP is known as intrasegment JMP. A far JMP is a jump where destination location is from a different segment. In this case both IP and CS are changed as specified in the destination. A far IMP is known as Inter segment JMP
Near and far jumps are further described as either direct or indirect. If the destination address for the jump is specified directly within the instruction, then the jump is described as direct. If the destination address for the jump is contained in a register or memory location, the jump is referred as indirect, because the 8086 has to access the specified register or memory location to get the required destination address.
As explained earlier, a near type jump instruction can cause the next instruction to be fetched from anywhere in the current code segment. To produce the new instruction fetch address, this instruction adds a 16-bit signed displacement contained in the instruction to the contents of the instruction pointer register. A 16 bit signed displacement means that the jump can be to a location anywhere from +32,767 to -32,768 bytes from the current instruction pointer location. A positive displacement usually means jump is ” ahead ” in the program, and a negative displacement usually means jump is ” backward ” in the program.
A special case of the direct near jump instruction is direct short jump. If the destination for the jump is within a displacement range of +127 to -128 bytes from the current instruction pointer location, the destination can be reached with just an 8 bit displacement.
b) J cond – Conditional Transfer Instructions:
These instructions will cause a jump to a label given in the instruction if the desired condition(s) occurs in the program before the execution of the instruction. The destination must be in the range of – 128 bytes to + 127 bytes from the address of the instruction after the conditional transfer instruction. If the jump is not taken, Program Execution Transfer Instructions in 8086 Microprocessor simply goes on to the next instruction.
Iteration Control Instructions:
These instructions are used to execute a series of instructions some number of times. The number is specified in the CX register. The CX register is automatically decremented by one, each time after execution of LOOP instruction. Until CX = 0, execution will jump to a destination specified by a label in the instruction.
The destination address for the jump must be in the range of – 128 bytes to + 127 bytes from the address of the instruction after the iteration control instruction. For LOOPE/LOOPZ and LOOPNE/LOOPNZ instructions there is one more condition for exit from loop, which is given below. If the loop is not taken, execution simply goes on to the next instruction after the iteration control instruction.