Home »
Embedded Systems
Subtract Two 8-bit numbers with Borrow in 8085 Microprocessor
In this tutorial, we will learn how to subtract two 8-bit numbers with borrow in 8085 Microprocessor?
By Samiksha Yadav Last updated : May 13, 2023
Subtraction of Two 8-bit numbers with Consideration of Borrow in 8085 Microprocessor
Given two 8-bit numbers, we have to subtract them in 8085 Microprocessor.
Algorithm
- Load the H-L pair with the address of first memory location.
- Move the content of H-L to accumulator.
- Increment H-L pair to next memory location.
- Load the register B with the memory location of second data.
- Initialize register C with 00H. this will store the borrow (if any).
- Subtract the content of accumulator with the content of register B and the result will be stored in accumulator automatically.
- If carry flag is set then increment register C.
- Increment H-L pair.
- Move result from accumulator to memory location 3002H.
- Increment H-L pair.
- Move borrow from register C to memory location 3003H.
Program
Address Mnemonics Operands
2000 LXI H,3000H
2003 MOV A, M
2004 INX H
2005 MOV B, M
2006 MVI C, 00H
2008 SUB B
2009 JNC 200D
200C INR c
200D INX H
200E MOV M, A
200F INX H
2010 MOV M, C
2011 HLT
Observation
INPUT:
3000H: 05H
3001H: 02H
OUTPUT:
3002H: 03H
3003H: 00H
Hence successfully subtracted two 8 bits numbers with consideration of borrow.