8085 Program to do an operation on two numbers based on the contents of X


Now let us see a program of Intel 8085 Microprocessor. In this program we will see how to do different operations based on choice.

Problem Statement:

Write 8085 Assembly language program to perform some operations on two 8-bit binary numbers base on choice.

Discussion:

In this program we are taking a choice. The choice value is stored at memory location 8000H (named as X). And the numbers are stored at location 8001H and 8002H. We are storing the result at location 8050H and 8051H.

Here if the choice is 00H, then it will perform addition, for 01H, it will perform subtraction, and for 02H, it will do the multiplication operation.

Input:

First input

Address
Data
.
.
.
.
.
.
8000
00
8001
97
8002
88
.
.
.
.
.
.

Second input

Address
Data
.
.
.
.
.
.
8000
01
8001
97
8002
88
.
.
.
.
.
.

Third input

Address
Data
.
.
.
.
.
.
8000
02
8001
05
8002
04
.
.
.
.
.
.

Flow Diagram:

Program:

Address
HEX Codes
Labels
Mnemonics
Comments
F000
21, 00, 80

LXI H,8000H
Point to get the choice
F003
7E

MOV A,M
Load choice into A
F004
FE, 00

CPI 00H
Compare for ADD
F006
CA,14, F0

JZ ADD
Jump to do Addition
F009
FE, 01

CPI 01H
Compare for SUB
F00B
CA,26, F0

JZ SUB
Jump to do Subtraction
F00E
FE, 02

CPI 02H
Compare for MUL
F010
CA, 38, F0

JZ MUL
Jump to do Multiplication
F013
76

HLT
Terminate the program
F014
23
ADD
INX H
Point to first operand
F015
7E

MOV A,M
Load operand to A
F016
23

INX H
Point to next operand
F017
86

ADD M
Add M with A
F018
6F

MOV L,A
Store A to L
F019
D2, 21, F0

JNC SKP1
If CY = 0, jump to SKP1
F01C
26, 01

MVI H,01H
Load H with 01H
F01E
C3, 49, F0

JMP STORE
Store result
F021
26, 00
SKP1
MVI H,00H
Clear HL
F023
C3, 49, F0

JMP STORE
Store HL as result
F026
23
SUB
INX H
Point to first operand
F027
7E

MOV A,M
Load operand to A
F028
23

INX H
Point to next operand
F029
96

SUB M
Subtract second operand from A
F02A
6F

MOV L,A
Store A to L
F02B
D2, 33, F0

JNC SKP2
If CY = 0, jump to SKP2
F02E
26, FF

MVI H,FFH
Load H with FFH
F030
C3, 49, F0

JMP STORE
Store result
F033
26, 00
SKP2
MVI H,00H
Clear HL
F035
C3, 49, F0

JMP STORE
Store HL as result
F038
23
MUL
INX H
Point to first operand
F039
5E

MOV E,M
Load operand to E
F03A
16, 00

MVI D,00H
Clear D register
F03C
23

INX H
Point to next operand
F03D
4E

MOV C,M
Load the second operand
F03E
21, 00, 00

LXI H,0000H
Clear HL pair
F041
19
LOOP
DAD D
Add first operand to HL
F042
0D

DCR C
Decrease C
F043
C2, 41, F0

JNZ LOOP
Jump to LOOP if Z = 0
F046
C3, 49, F0

JMP STORE
Store result
F049
22, 50, 80
STORE
SHLD 8050H
Store result from HL
F04C
76

HLT
Terminate the program

Output:

First output

Address
Data
.
.
.
.
.
.
8050
1F
8051
01
.
.
.
.
.
.

Second output

Address
Data
.
.
.
.
.
.
8050
0F
8051
00
.
.
.
.
.
.

Third output

Address
Data
.
.
.
.
.
.
8050
14
8051
00
.
.
.
.
.
.



Updated on: 30-Jul-2019

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements