BRANCHING INSTRUCTIONS


instructions, which are used to for conditional and unconditional jump, subroutine call and return and restart. The branching instruction alter the normal sequential flow.

Unconditional Jump Instructions              :

Opcode Operand Description
JMP 16-bit address Jump unconditionally

1) JMP instruction:

The format for this instruction is JMP address or JMP LABEL.

This is an unconditional jump instruction. With the execution of this instruction, the program jump to the address (or label) specified with the instruction. This is a three byte instruction and no flag is affected. In fact during the execution of JMP address (label) instruction, the address of the label is copied in the program counter; and whenever the program fetches the next instruction the program counter will send the address of this given label.

[PC] < - [LABEL]

Operand Bytes Flags Affected M-Cycles T-States
16-bit address 3 None 3 10

Conditional Jump Instructions              :

Opcode Description Status Flags
JNZ Jump if No Zero Z = 0
JZ Jump if Zero Z = 1
JC Jump if Carry CY = 1
JNC Jump if No Carry CY = 0
JP Jump if Positive S = 0
JM Jump if Minus S = 1
JPE Jump if Parity Even P = 1
JPO Jump if Parity Odd P = 0

The format for These instruction are INSTRUCTION address or INSTRUCTION LABEL. like,
JNZ LABEL.

Condition Bytes Flags Affected M-Cycles T-States
True 3 None 3 10
Not True 3 None 2 7

1) JNZ instruction:

This is mnemonic for Jump if the result is not zero.When this instruction is executed, the program jumps to the instruction specified by the address (or label), if the result is not zero; otherwise it will proceed to the next instruction. Here the result of the preceding instruction is considered.

In this case the address (or label) is copied in the program counter if zero flag is reset (Z = 0).

[PC] < - LABEL if Z = 0.

For example,

Label Mnemonics  Operand
----
----
DCR C
JNZ NEXT
MOV A,M
NEXT STA 2500H
HLT

For the execution of JNZ instruction, the result of C-register will be considered. If [C] ≠ 0 (Z = 0), it will jump to the instruction (STA 2500 H) specified by the label NEXT, otherwise it will jump to the next instruction (MOV A, M).

2) JZ instruction:

This is mnemonic for Jump if the result is zero.The condition of this instruction is reverse to that of JNZ address. In this case the program will jump to the instruction specified by the address (or label), if the result of the preceding instruction is zero (Z = 1) otherwise it will proceed to the next instruction in the normal sequence.

The address of the label will be copied in the program counter if Z flag is set (or result is zero).

[PC] < - LABEL if Z = 1.

3) JC instruction:

This is mnemonic for Jump if carry.The program will jump to the instruction specified by the address (label) if the CY flag is set (CY = 1) which is modified by the preceding instruction. However, if the carry is reset (CY = 0), it will proceed to the next instruction of the normal sequence. The condition of this instruction is opposite to that of the JNC address.

In this case the address of the label will be copied in the program counter if CY = 1 or CY is set.

[PC] < - LABEL if CY = 1.

4) JNC instruction:

This is mnemonic for Jump if no carry.During the execution of this instruction, it will check up the Carry flag modified by the preceding instruction. If there is no carry (CY = 0 or CY flag is reset), the program will jump to the instruction specified by the address (or label) otherwise it will proceed to the next instruction of the normal sequence.

In this case the address of the label will be copied in the program counter if CY = 0 or CY is reset.

[PC] < - LABEL if CY = 0.

5) JP instruction:

This is mnemonic for Jump if Positive.If the result of the preceding instruction is positive or sign flag is reset (S = 0), the program will jump to the instruction specified by the address (label). However, if the condition is not satisfied it will proceed to the next instruction of the normal sequence.

[PC] < - LABEL if S = 0.

6) JM instruction:

This is mnemonic for Jump if Minus.When this instruction is executed, the program will jump to the instruction specified by the address (label) if the result of the preceding instruction is minus or sign flag is set (S = 1) otherwise it will proceed to the next instruction of the normal sequence.

[PC] < - LABEL if S = 1.

7) JPE instruction:

This is mnemonic for Jump if Parity is Even.If the parity is even or parity flag is set (P = 1) as a result of the preceding instruction, the program will jump to the instruction specified by the address (label) otherwise next instruction of the normal sequence will be executed.

[PC] < - LABEL if P = 1.

8) JPO instruction:

This is mnemonic for Jump if Parity is Odd.If the parity is odd or parity flag is reset (P = 0) as a result of the preceding instruction, the program will jump to the instruction specified by the address (label) otherwise next instruction of the normal sequence will be executed.

[PC] < - LABEL if P = 0.

Unconditional Call Instructions              :

Opcode Operand Description
CALL 16-bit address Call unconditionally

1) CALL instruction:

This is mnemonic for Calls the addressed subroutine program.This is the format for unconditional call instruction which is of three bytes. The current contents of program counter are saved on the Stack and the address specified with CALL instruction is copied in the program counter.

i.e. [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

For example,

Image of CALL

When the instruction CALL 2300 H is executed, the address of the program counter will be 2105 H. The address of the program counter will be saved on the stack. The subroutine program ends at the instruction RET i.e. RET instruction will be the last instruction of the subroutine program. The RET instruction takes the computer back to the main program.In the above program, after the execution of RET instruction PC = 2105 H.

Operand Bytes Flags Affected M-Cycles T-States
16-bit address 3 None 5 18

Conditional Call Instructions              :

Opcode Description Status Flags
CC Call if Carry CY = 1
CNC Call if No Carry CY = 0
CP Call if Positive S = 0
CM Call if Minus S = 1
CZ Call if Zero Z = 1
CNZ Call if No Zero Z = 0
CPE Call if Parity Even P = 1
CPO Call if Parity Odd P = 0

Condition Bytes Flags Affected M-Cycles T-States
True 3 None 5 18
Not True 3 None 2 9

1) CC instruction:

This is mnemonic for Call if carry.The addressed subroutine will be called by the computer, there is a carry (or carry flag is set ; CY = 1) as per the result of the preceding instruction.

if CY = 1 or there is a carry, then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

2) CNC instruction:

This is mnemonic for Call if no carry.This instruction will check the carry flag. If the carry flag is reset (or CY=0) as per the executed preceding instruction, then the computer will call the addressed subroutine program.

if CY = 0 or there is no carry, then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

3) CP instruction:

This is mnemonic for Call if positive.In this CALL instruction too the sign flag will be checked. If the result of the preceding instruction is positive or sign flag is reset (S = 0), then the computer will call the subroutine program specified by the address.

if S = 0, then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

4) CM instruction:

This is mnemonic for Call if minus.During the execution of this instruction the sign flag will be checked. If the result of the preceding instruction is negative or sign flag is set (S = 1), then only the computer will call the subroutine program specified by the address.

if S = 1, then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

5) CZ instruction:

This is mnemonic for Call if zero.It will call the subroutine (specified by the address) if zero fags is set.

if Z = 1 or the result is 1 zero then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

6) CNZ instruction:

This is mnemonic for Call if not zero.This instruction will call the subroutine program specified by the address provided the zero flag is reset.

if Z = 0 or the result is not zero then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

7) CPE instruction:

This is mnemonic for Call if parity is even.The computer will call the addressed subroutine program, if the parity of the result of the preceding instruction is even (or parity flag is set; P = 1), then.

if P = 1, then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

8) CPO instruction:

This is mnemonic for Call if parity is odd.If the parity of the result of the preceding instruction is odd (or parity flag is reset; P = 0), then the computer will call the addressed subroutine program.

if P = 0, then [SP1] < - [PCH] , [SP2] < - [PCL] and [PC] < - address.

Unconditional Return Instructions              :

Opcode Operand Description
RET None Return unconditionally

1) RET instruction:

The RET instruction takes the computer back to the main program. The return saved (or pushed) on to the stack will be popped back to the program counter.

Operand Bytes Flags Affected M-Cycles T-States
None 1 None 3 10

Conditional Return Instructions              :

Opcode Description Status Flags
RC Return if Carry CY = 1
RNC Return if No Carry CY = 0
RP Return if Positive S = 0
RM Return if Minus S = 1
RZ Return if Zero Z = 1
RNZ Return if No Zero Z = 0
RPE Return if Parity Even P = 1
RPO Return if Parity Odd P = 0

All the above return instructions are one byte instructions. If the specified condition is satisfied, it will return to the main program; otherwise the execution of the next instruction in the subroutine will be carried out. Further the return instruction will pop the return address to the program counter.

Condition Bytes Flags Affected M-Cycles T-States
True 1 None 3 12
Not True 1 None 1 6

For example, we consider the instruction RNC.It will check the carry flag. Only if the carry flag is reset (CY = 0 or no carry), the computer return to main program.

SOFTWARE INTERRUPTS              :

The 8085 microprocessor has eight software interrupts namely, RST 0, RST 1, RST 2, RST 3, RST 4, RST 5, RST 6 and RST 7.These instructions are single byte instructions. When an interrupt occurs, a CALL instruction to a predetermined location of the memory is executed. The effect of each restart instruction is shown in table.

Instructions Restart Address
RST 0 CALL 0000 H
RST 1 CALL 0008 H
RST 2 CALL 0010 H
RST 3 CALL 0018 H
RST 4 CALL 0020 H
RST 5 CALL 0028 H
RST 6 CALL 0030 H
RST 7 CALL 0038 H

For example in the main program RST2 instruction is given, and when this instruction is executed the contents of the program counter is pushed onto the stack. Then the program counter jumps to the address 0010 H. The subroutine located from 0010 H to 0017 H is executed, with the RET instruction as the last instruction of the subroutine program. So as the RET instruction is executed it returns to the main program.

Similarly, if another restart instruction RST4 is encountered in the main program, then the contents of the program counter are again pushed onto the stack. The program jumps to the subroutine program whose starting address is given by 0020 H. After the execution of this subroutine program it returns to the main program as shown in figure

Image of RST