8085 program to subtract two 8-bit numbers with or without borrow


In this program we will see how to subtract two 8-bit numbers using 8085 microprocessor.

Problem Statement

Write 8085 Assembly language program to subtract two 8-bit numbers with or without borrow and store the result at locations 8050H and 8051H.

Discussion

In 8085, the SUB instruction is used 2’s complemented method for subtraction. When the first operand is larger, the result will be positive. It will not enable the carry flag after completing the subtraction. When the result is negative, then the result will be in 2’s complemented form and carry flag will be enabled.

We are using two numbers at location 8000H and 8001H. When the numbers are 78H and 5DH, then the result will be (78 – 5D = 1B) and when the numbers are 23H and CFH, then the result will be (23 – CF = 154) Here 1 indicates the number is negative. The actual result is 54H. It is in 2’s complemented form.

Input

first output

AddressData
.
.
.
.
.
.
800078
80015D
.
.
.
.
.
.

second output

AddressData
.
.
.
.
.
.
800023
8001CF
.
.
.
.
.
.

Flow Diagram

AddressHEXCodesLabelsMnemonicsComments
F0000E, 00
MVI C,00HClear C register
F00221, 00, 80
LXI H,8000HLoad initial address to get operand
F0057E
MOV A,MLoad Acc with memory element
F00623
INX HPoint to next location
F00746
MOV B, MLoad B with second operand
F00890
SUB BSubtract B from A
F009D2, 0D, F0
JNC STOREWhen CY = 0, go to STORE
F00C0C
INR CIncrease C by 1
F00D21, 50, 80STORELXI H,8050HLoad the destination address
F01077
MOV M, AStore the result
F01123
INX HPoint to next location
F01271
MOV M, CStore the borrow
F01376
HLTTerminate the program

Output

first output

AddressData
.
.
.
.
.
.
80501B
805100
.
.
.
.
.
.

second output

AddressData
.
.
.
.
.
.
805054
805101
.
.
.
.
.
.

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements