Branching Instructions
Branching Instructions
Branching Instructions
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:
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. NEAR – This procedure targets within the same code segment. (Intra-segment)
ii. FAR - In this procedure, the target is outside the segment and the size of the pointer is
double word. (Inter-segment)
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.
It checks whether the carry flag is set or not. If yes, then jump takes place, that is: If CF = 1,
then jump.
It checks whether the carry flag is reset or not. If yes, then jump takes place, that is: If CF = 0,
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.
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 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.
CALL subprogram_name
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.
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 Instruction-
Example:
This instruction is used to repeat a group of instruction some number of times until CX =0 and
ZF = 0
Example:
LOOP NEXT
LOOPNE/LOOPNZInstruction-
This instruction is used to repeat a group of instruction some number of times until CX =0 and
ZF = 1
Example:
DEC BX
LOOPNE NEXT