Table of Contents
ToggleIn the article, some examples of Microprocessor 8085 addition and subtraction programs in assembly language programming (ALP) are explained. You need to learn the instruction set of 8085 in detail before programming.
One program can be performed in multiple ways. Here they are mentioned as Program 1, Program 2 …
Addition Programs in 8085
Addition of two 8-bit numbers without carry
Add the contents of memory locations 4000H and 4001H and place the result in memory location 4002H.
Program:
LXI H, 4000H ; Load HL with 4000H
MOV A, M ; Copy the operand from memory (H-L pair) into accumulator
INX H ; Increment memory address by 1 (HL points 4001H)
ADD M ; Add accumulator with second operand, result stored in accumulator
INX H ; Increment memory address by 1 (HL points 4002H)
MOV M, A ; Store result at 4002H
HLT ; Terminate program execution
Sample Example:
(4000H) = 23H
(4001H) = 69H
Result = 23H + 69H = 8CH
Addition of two 8-bit numbers with carry
Add the contents of memory locations 2000H and 2001H and place the result in the memory locations 2002Hand 2003H.
Program:
LXI H, 2000H ; Load HL with 2000H
MOV A, M ; Copy the operand from memory (H-L pair) into accumulator
INX H ; Increment memory address by 1 (HL points 2001H)
ADD M ; Add accumulator with second operand, result stored in accumulator
INX H ; HL Points 2002H
MOV M, A ; Store the lower byte of result at 2002H
MVI A, 00 ; Initialize higher byte result with 00H
ADC A ; Add carry in the high byte result
INX H ; HL Points 2003H
MOV M, A ; Store the higher byte of result at 2003H
HLT ; Terminate program execution
Sample Example:
(2000H) = 98H
(2001H) = F7H
Result = 98H + F7H = 018FH
(2002H) = 8FH
(2003H) = 01H
Addition of two 16-bit numbers in 8085
Add the 16-bit number in memory locations 4000H and 4001H to the 16-bit number in memory locations 4002H and 4003H. The most significant eight bits of the two numbers to be added are in memory locations 4001H and 4003H.
Store the result in memory locations 4004H and 4005H with the most significant byte in memory location 4005H.
Program 1:
LHLD 4000H ; Get first 16-bit number in H-L register pair
XCHG ; Save first 16-bit number in D-E register pair
LHLD 4002H ; Get second 16-bit number in HL
MOV A, E ; Get lower byte of the first number
ADD L ; Add lower byte of the second number
MOV L, A ; Store result in L register
MOV A, D ; Get higher byte of the first number
ADC H ; Add higher byte of the second number with CARRY
MOV H, A ; Store result in H register
SHLD 4004H ; Store 16-bit result in memory locations 4004H and 4005H.
HLT ; Terminate program execution
Program 2:
LHLD 4000H ; Get first 16-bit number in H-L register pair
XCHG ; Copy first 16-bit number in DE register pair
LHLD 4002H ; Get second 16-bit number in HL
DAD D ; Add DE and HL
SHLD 4004H ; Store 16-bit result in memory locations 4004H and 4005H.
HLT ; Terminate program execution
Sample Example:
(4000H) = 20H
(4001H) = 3AH
(4002H) = 14H
(4003H) = 2BH
Result = 203A + 142BH = 3465H
(4004H) = 34H
(4005H) = 65H
Subtraction Programs in 8085
Subtraction of two 8-bit numbers in 8085
Subtract the contents of memory location 1001H from the memory location 1000H and place the result in memory location 1002H.
Program:
LXI H, 1000H ; Load HL with 4000H
MOV A, M ; Copy the operand from memory (H-L pair) into accumulator
INX H ; HL points 1001H
SUB M ; Subtract second operand from accumulator and store result in accumulator
INX H ; HL points 1002H
MOV M, A ; Store result at 1002H.
HLT ; Terminate program execution
Sample Example:
(1000H) = 34H
(1001H) = 23H
Result = 34H – 23H = 11H
Subtraction of two 16-bit numbers in 8085
Subtract the 16-bit number in memory locations 4002H and 4003H from the 16-bit number in memory locations 4000H and 4001H. The most significant eight bits of the two numbers are in memory locations 4001H and 4003H.
Store the result in memory locations 4004H and 4005H with the most significant byte in memory location 4005H.
Program:
LHLD 4000H ; Get first 16-bit number in HL
XCHG ; Save first 16-bit number in DE
LHLD 4002H ; Get second 16-bit number in HL
MOV A, E ; Get lower byte of the first number
SUB L ; Subtract lower byte of the second number
MOV L, A ; Store the result in L register
MOV A, D ; Get higher byte of the first number
SBB H ; Subtract higher byte of second number with borrow
MOV H, A ; Store 16-bit result in memory locations 4004H and 4005H.
SHLD 4004H ; Store 16-bit result in memory locations 4004H and 4005H.
HLT ; Terminate program execution.
Sample Example:
(4000H) = 20H
(4001H) = 3AH
(4002H) = 14H
(4003H) = 2BH
Result = 203AH – 142BH = 0C0FH
(4004H) = 0CH
(4005H) = OFH
Recent posts
Related posts:
- Terminology Used in Microprocessor and Microcontroller
- CISC and RISC Processor Architecture
- Von Neumann and Harvard Architecture
- Basics of Microprocessor and Microcontroller
- Introduction to Microprocessor 8085
- Architecture of 8085 Microprocessor
- Pin Diagram of 8085 Microprocessor and Pin Description
- Addressing Modes in 8085 Microprocessor
- Data Transfer Instructions in 8085 Microprocessor
- Arithmetic Instructions in 8085 Microprocessor
- Logical Instructions in 8085 Microprocessor
- Branching instructions in 8085 Microprocessor
- Machine Control Instructions in 8085 Microprocessor
- Timing Diagram of 8085 Instructions
- Stack and Subroutine in 8085 Microprocessor
- Interrupts in 8085 Microprocessor
- Assembler Directives of 8085 Microprocessor
- Simple Data Transfer Program in 8085 Microprocessor
- Programs on Logical Instructions in 8085 Microprocessor
- Multiplication Programs in 8085 Microprocessor
- Division Programs in 8085 Microprocessor
- Introduction to Assembly Language Programming
- 8085 Program to Find the Largest Number in an Array of Data
- 8085 Program to Count Negative Numbers | ALP to Count Negative Numbers
- 8085 Program to Find the Smallest Number in An Array of Data
- 8085 Program to Arrange an Array of Data in Ascending Order
- 8085 Program to Arrange an Array of Data in Descending Order
- 8085 Program to Find the Square of a Number from 0 to 9 Using a Table of Square
Some really nice stuff on this web site , I like it.
gread