Branch Type Instructions:
Branch Type Instructions These type of instructions can be unconditional or conditional branch instruction. and are given below:
- Unconditional Branch
-
- JMP 16-bit Address (Label)
- CALL 16-bit Address (Label)
- RET ; Return from Subroutine
- RST n ; restart is a one byte call instruction, and jumps to the instruction at restart addre.
- Conditional Branch
-
- JZ 16-bit Address (Label)
- JNZ 16-bit Address (Label)
- JC 16-bit Address (Label)
- JNC 16-bit Address (Label)
- JP 16-bit Address (Label); if result is positive
- JM 16-bit Address (Label); if result is Minus
- JPE 16-bit Address (Label); If even parity
- JPO 16-bit Address (Label); if odd parity
- Unconditional Call
- CALL 16-bit Address
-
- Conditional Call
- Opcode Description Flag Status
- CC Call on Carry CY = 1
- CNC Call on no Carry CY = 0
- CP Call on positive S = 0
- CM Call on minus S = 1
- CZ Call on zero Z = 1
- CNZ Call on no zero Z = 0
- CPE Call on parity even P = 1
- CPO Call on parity odd P = 0
Example programs Ex-1: WAP to AL add an array of 10 numbers stored in memory and store the result back in memory at the end of memory
Answer:
store the count in register C, and every time a byte is added the counter is decremented by 1 and address incremented by 1. The process will terminate when the count becomes zero(‘0’)
LXI H, 2020h
MVI C, 0Ah
MVI A, 0
NEXT: ADD M
INX H
DCR C
JNZ NEXT
INX H
MOV M, A
HLT
Ex-2: Modify the above program to take care of carries. If a carry is generated as a result of addition then keep a record of such carries. At the end of addition process, the carry if any is also to be stored in memory.
Answer:
LXI H, 2020h
MVI C, 0Ah
MVI A, 0
MVI B, 0 ; to keep the carry
BACK: ADD M
JNC FORWARD
INR B ; increment for carry
FORWARD: INX H
DCR C
JNZ BACK
INX H
MOV M, A
INX H
MOV M, B ; store carries
HLT
Ex-3: A set of numbers stored in memory the numbers are a mix of positive and negative. WAP in AL to count the number of +ve and -ve numbers. The count of total entries is stored at the beginning of the array at location 2020h.
Answer:
LXI H, 2020h
MVI A, 0
MVI B, 0
MOV D, M
MOV C, M ; store total reading in register C as a counter
BACK : INX H
MOV A, M
RLC ; rotate accumulator left C<- A7, A0<- A7, rest AN ← AN-1
JNC NEXT
INR B ; B contain the count of -ve numbers.
NEXT : DCR C
JNZ BACK
MOV A, D
SUB B ; Accumulator Now contain count of +ve numbers
HLT
Ex-4: WAP in AL to transfer a bulk of 100 bytes stored in memory starting at location 2020h to another location away from the array so that the copied do not overlap with the stored data.
Answer:
LXI H, 2020h
MVI C, 64h
LXI D, 2085h
BACK: MOV A, M
XCHG
MOV M, A
XCHG
INX H
INX D
DCR C
JNZ BACK
HLT