8085 Program to Subtract two multi-Byte numbers


Now let us see a program of Intel 8085 Microprocessor. This program is mainly for subtracting multi Byte numbers.

Problem Statement:

Write 8085 Assembly language program to add two multi-Byte numbers.

Discussion:

We are using 3-Byte numbers. The numbers are stored into the memory at location 8001H and 8004H. One additional information is stored at location 8000H. In this place we are storing the Byte count. The result is stored at location 8050H.

We are taking the address of first operand block address into DE register pair, and the second operand block address into HL pair. The BC register pair is storing the destination address to store the result. At first we are clearing the carry flag. In 8085 there is no instruction to set the CY flag to 0, so we need two consecutive instructions. STC and CMC, the first one is set the CY to 1, and then complement it to make it 0. We are taking the number from memory and performing subtract with borrow instruction SBB to get the result. Thus the whole result is generated.

Input:

Address
Data
.
.
.
.
.
.
8000
03
8001
73
8002
21
8003
65
8004
88
8005
51
8006
27
.
.
.
.
.
.

Flow Diagram:

Program:

Address
HEX Codes
Labels
Mnemonics
Comments
F000
11, 01, 80

LXI D,8001H
Point to first operand
F003
21, 04, 80

LXI H,8004H
Point to second operand
F006
01, 50, 80

LXI B,8050H
Point destination address
F009
37

STC
Set the carry
F00A
3F

CMC
Complement carry
F00B
1A
LOOP
LDAX D
Load A from memory pointed by DE
F00C
9E

SBB M
Subtract memory element and borrow
F00D
02

STAX B
Store result into memory pointed by BC
F00E
23

INX H
Increase HL pair
F00F
13

INX D
Increase DE pair
F010
03

INX B
Increase BC pair
F011
3A, 00, 80

LDA 8000H
Load the size into A
F014
3D

DCR A
Decrease A by 1
F015
32, 00, 80

STA 8000H
Store updated size into memory
F018
C2, 0B, F0

JNZ LOOP
If Z = 0, jump to LOOP
F01B
76

HLT
Terminate the program

Output:

Address
Data
.
.
.
.
.
.
8050
EB
8051
CF
8052
3D
.
.
.
.
.
.


Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements