Branch Type Instructions:
Branch Type Instructions These type of instructions can be unconditional or conditional branch instruction. and are given below:

    Unconditional Branch

    1. JMP 16-bit Address (Label)
    2. CALL 16-bit Address (Label)
    3. RET ; Return from Subroutine
    4. RST n ; restart is a one byte call instruction, and jumps to the instruction at restart addre.
    Conditional Branch

    1. JZ 16-bit Address (Label)
    2. JNZ 16-bit Address (Label)
    3. JC 16-bit Address (Label)
    4. JNC 16-bit Address (Label)
    5. JP 16-bit Address (Label); if result is positive
    6. JM 16-bit Address (Label); if result is Minus
    7. JPE 16-bit Address (Label); If even parity
    8. JPO 16-bit Address (Label); if odd parity
    Unconditional Call

  1. CALL 16-bit Address
    1. Conditional Call

 

  1. Opcode Description Flag Status
  2. CC Call on Carry CY = 1
  3. CNC Call on no Carry CY = 0
  4. CP Call on positive S = 0
  5. CM Call on minus S = 1
  6. CZ Call on zero Z = 1
  7. CNZ Call on no zero Z = 0
  8. CPE Call on parity even P = 1
  9. 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

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!