🏁
T9
/
5️⃣
Sem 5
/
Practicals
Practicals
/
MI
MI
/
Lab 3

Lab 3

Lab 3 : PROGRAMMING BASED ON BRANCH OPERATIONS
OBJECTIVE
To familiar with the use of branch operation related instructions in 8085 programming
PRELAB
Read and understand utilization of the instructions related to branch operations.
OVERVIEW OF BRANCH INSTRUCTIONS
Opcode
Operand
Description
JMP
16-bit
Jump on the 16-bit memory address
JC
16-bit
Jump on Carry
JNC
16-bit
Jump on no Carry
JZ
16-bit
Jump on Zero
JNZ
16-bit
Jump on no Zero
JP
16-bit
Jump on Plus
JM
16-bit
Jump on Minus
JPE
16-bit
Jump on Even Parity
JPO
16-bit
Jump on Odd Parity
EXERCISE
1. Write a program to multiply two 8 bit data stored at location 2101H and 2102H.
ORG 2100H
LXI H, 2101H
MOV A, M
INX H
MOV B, M
MVI C, 00H
MULTIPLY:
    CMP B
    JZ END
    ADD C
    MOV C, A
    DCR B
    JMP MULTIPLY
END:
LXI H, 2103H
MOV M, C
HLT
2. Write a program to add an array of 10 bytes data stored from location 5000H to 5009H and store the result at 500AH and 500BH.
ORG 5000H
DB 01H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H, 0AH

ORG 500AH
DB 00H, 00H

ORG 2000H
LXI H, 5000H
MVI C, 00H
MVI D, 00H
MVI B, 0AH

ADD_LOOP:
    MOV A, M
    ADD C
    MOV C, A
    INX H
    DCR B
    JNZ ADD_LOOP

LXI H, 500AH
MOV M, C
MOV A, D
MOV M, A

HLT
3. Write a program to subtract an array of 10 bytes data stored from location 5000H to 5009H and store the result at 500AH and 500BH.
ORG 5000H
DB 10H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H, 0AH

ORG 500AH
DB 00H, 00H

ORG 2000H
LXI H, 5000H
MOV A, M
INX H
MVI B, 09H

SUB_LOOP:
    MOV C, M
    SUB C
    INX H
    DCR B
    JNZ SUB_LOOP

LXI H, 500AH
MOV M, A
MOV A, L
MOV M, A

HLT
4. Write a program to find largest and smallest numbers in block of array from 2100H to 2109H. Store the result at location 210AH and 210BH.
ORG 2100H
DB 05H, 03H, 09H, 01H, 07H, 02H, 08H, 06H, 04H, 00H

ORG 210AH
DB 00H

ORG 210BH
DB 00H

ORG 2000H
LXI H, 2100H
MOV A, M
MOV B, A
MOV C, A
INX H
MVI D, 09H

FIND_LOOP:
    MOV A, M
    CMP B
    JG UPDATE_LARGEST
    CMP C
    JL UPDATE_SMALLEST
    INX H
    DCR D
    JNZ FIND_LOOP
    JMP STORE_RESULTS

UPDATE_LARGEST:
    MOV B, A
    JMP FIND_LOOP

UPDATE_SMALLEST:
    MOV C, A
    JMP FIND_LOOP

STORE_RESULTS:
LXI H, 210AH
MOV M, B
LXI H, 210BH
MOV M, C

HLT
5. Write an ALP to sort an array of 10 elements from 2100H in ascending order.
ORG 2100H
DB 05H, 03H, 09H, 01H, 07H, 02H, 08H, 06H, 04H, 0AH

ORG 2000H
LXI H, 2100H
MVI B, 0AH
MVI C, 00H

OUTER_LOOP:
    MOV D, M
    INX H
    MOV E, M
    INX H
    MVI A, 00H

INNER_LOOP:
    CMP D
    JC NO_SWAP
    MOV M, D
    MOV A, 01H
    INX H
    MOV D, E
    MOV E, M
    JMP INNER_LOOP

NO_SWAP:
    DCR B
    JNZ OUTER_LOOP

HLT
6. Write an ALP to sort an array of 10 elements from 2100H in descending order.
ORG 2100H
DB 05H, 03H, 09H, 01H, 07H, 02H, 08H, 06H, 04H, 0AH

ORG 2000H
LXI H, 2100H
MVI B, 0AH
MVI C, 00H

OUTER_LOOP:
    MOV D, M
    INX H
    MOV E, M
    INX H
    MVI A, 00H

INNER_LOOP:
    CMP D
    JZ NO_SWAP
    JC SWAP
    JMP NO_SWAP

SWAP:
    MOV M, D
    INX H
    MOV M, E
    MOV A, 01H
    INX H
    MOV D, E
    MOV E, M
    JMP INNER_LOOP

NO_SWAP:
    DCR B
    JNZ OUTER_LOOP

HLT
🏁
T9
/
5️⃣
Sem 5
/
Practicals
Practicals
/
MI
MI
/
Lab 3

Lab 3

Lab 3 : PROGRAMMING BASED ON BRANCH OPERATIONS
OBJECTIVE
To familiar with the use of branch operation related instructions in 8085 programming
PRELAB
Read and understand utilization of the instructions related to branch operations.
OVERVIEW OF BRANCH INSTRUCTIONS
Opcode
Operand
Description
JMP
16-bit
Jump on the 16-bit memory address
JC
16-bit
Jump on Carry
JNC
16-bit
Jump on no Carry
JZ
16-bit
Jump on Zero
JNZ
16-bit
Jump on no Zero
JP
16-bit
Jump on Plus
JM
16-bit
Jump on Minus
JPE
16-bit
Jump on Even Parity
JPO
16-bit
Jump on Odd Parity
EXERCISE
1. Write a program to multiply two 8 bit data stored at location 2101H and 2102H.
ORG 2100H
LXI H, 2101H
MOV A, M
INX H
MOV B, M
MVI C, 00H
MULTIPLY:
    CMP B
    JZ END
    ADD C
    MOV C, A
    DCR B
    JMP MULTIPLY
END:
LXI H, 2103H
MOV M, C
HLT
2. Write a program to add an array of 10 bytes data stored from location 5000H to 5009H and store the result at 500AH and 500BH.
ORG 5000H
DB 01H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H, 0AH

ORG 500AH
DB 00H, 00H

ORG 2000H
LXI H, 5000H
MVI C, 00H
MVI D, 00H
MVI B, 0AH

ADD_LOOP:
    MOV A, M
    ADD C
    MOV C, A
    INX H
    DCR B
    JNZ ADD_LOOP

LXI H, 500AH
MOV M, C
MOV A, D
MOV M, A

HLT
3. Write a program to subtract an array of 10 bytes data stored from location 5000H to 5009H and store the result at 500AH and 500BH.
ORG 5000H
DB 10H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H, 0AH

ORG 500AH
DB 00H, 00H

ORG 2000H
LXI H, 5000H
MOV A, M
INX H
MVI B, 09H

SUB_LOOP:
    MOV C, M
    SUB C
    INX H
    DCR B
    JNZ SUB_LOOP

LXI H, 500AH
MOV M, A
MOV A, L
MOV M, A

HLT
4. Write a program to find largest and smallest numbers in block of array from 2100H to 2109H. Store the result at location 210AH and 210BH.
ORG 2100H
DB 05H, 03H, 09H, 01H, 07H, 02H, 08H, 06H, 04H, 00H

ORG 210AH
DB 00H

ORG 210BH
DB 00H

ORG 2000H
LXI H, 2100H
MOV A, M
MOV B, A
MOV C, A
INX H
MVI D, 09H

FIND_LOOP:
    MOV A, M
    CMP B
    JG UPDATE_LARGEST
    CMP C
    JL UPDATE_SMALLEST
    INX H
    DCR D
    JNZ FIND_LOOP
    JMP STORE_RESULTS

UPDATE_LARGEST:
    MOV B, A
    JMP FIND_LOOP

UPDATE_SMALLEST:
    MOV C, A
    JMP FIND_LOOP

STORE_RESULTS:
LXI H, 210AH
MOV M, B
LXI H, 210BH
MOV M, C

HLT
5. Write an ALP to sort an array of 10 elements from 2100H in ascending order.
ORG 2100H
DB 05H, 03H, 09H, 01H, 07H, 02H, 08H, 06H, 04H, 0AH

ORG 2000H
LXI H, 2100H
MVI B, 0AH
MVI C, 00H

OUTER_LOOP:
    MOV D, M
    INX H
    MOV E, M
    INX H
    MVI A, 00H

INNER_LOOP:
    CMP D
    JC NO_SWAP
    MOV M, D
    MOV A, 01H
    INX H
    MOV D, E
    MOV E, M
    JMP INNER_LOOP

NO_SWAP:
    DCR B
    JNZ OUTER_LOOP

HLT
6. Write an ALP to sort an array of 10 elements from 2100H in descending order.
ORG 2100H
DB 05H, 03H, 09H, 01H, 07H, 02H, 08H, 06H, 04H, 0AH

ORG 2000H
LXI H, 2100H
MVI B, 0AH
MVI C, 00H

OUTER_LOOP:
    MOV D, M
    INX H
    MOV E, M
    INX H
    MVI A, 00H

INNER_LOOP:
    CMP D
    JZ NO_SWAP
    JC SWAP
    JMP NO_SWAP

SWAP:
    MOV M, D
    INX H
    MOV M, E
    MOV A, 01H
    INX H
    MOV D, E
    MOV E, M
    JMP INNER_LOOP

NO_SWAP:
    DCR B
    JNZ OUTER_LOOP

HLT