8085 Program to add the contents of N word locations

MicrocontrollerMicroprocessor8085

Now let us see a program of Intel 8085 Microprocessor. In this program we will see how to add the contents of N word locations.

Problem Statement:

Write 8085 Assembly language program to add N 16-bit numbers stored into memory

Discussion:

The 16-bit numbers are stored into memory location 8001H onwards. The value of N is stored at location 8000H. After addition, the result will be stored at location 8050H onwards.

In 8085 we have few number of registers. So we are storing the count into memory, when we need to update it, we will fetch it from memory, update it and then again store it into memory.

Here the 16-bit numbers are stored at location DE and HL, by using DAD instruction we are adding them.

Input:

First input

Address
Data
.
.
.
.
.
.
8000
03
8001
34
8002
12
8003
78
8004
56
8005
BC
8006
9A


.
.
.
.
.
.

Flow Diagram:

Program:

Address
HEX Codes
Labels
Mnemonics
Comments
F000
31, 00, C0

LXI SP,C000H
Initialize the stack pointer
F003
21, 00, 00

LXI H,0000H
Clear HL pair
F006
22, 52, 80

SHLD 8052H
Store HL content to 8052H and 8053H
F009
01, 00, 80

LXI B,8000H
Point address to Get the number count
F00C
0A

LDAX B
Get count to Accumulator
F00D
32, 00, 90

STA 9000H
Store the Acc content temporarily
F010
03
LOOP
INX B
Point to get lower Byte
F011
0A

LDAX B
Load acc with memory content
F012
5F

MOV E,A
Store acc to E
F013
03

INX B
Point to get upper Byte
F014
0A

LDAX B
Load acc with memory content
F015
57

MOV D,A
Store acc to D
F016
19

DAD D
Add DE with HL
F017
D2, 23, F0

JNC SKIP
Jump to skip if CY = 0
F01A
E5

PUSH H
Push HL content to stack
F01B
2A, 52, 80

LHLD 8052H
Load HL with the content of 8052H and 8253H
F01E
23

INX H
Increase HL content
F01F
22, 52, 80

SHLD 8052H
Store the HL content to 8052H and 8053H
F022
E1

POP H
Get back HL content from stack
F023
3A, 00, 90
SKIP
LDA 9000H
Load temporarily stored data
F026
3D

DCR A
Decrease A by 1
F027
32, 00, 90

STA 9000H
Store the updated value
F02A
C2, 10, F0

JNZ LOOP
If Z = 0 go to Loop
F02D
22, 50, 80

SHLD 8050H
Store HL content to 8050H and 8051H
F030
76

HLT
Terminate the program

Output:

First output

Address
Data
.
.
.
.
.
.
8050
68
8051
03
8052
01
8053
00
.
.
.
.
.
.
raja
Updated on 30-Jul-2019 22:30:25

Advertisements