Subtraction of Two 8 Bit Numbers using 8085 microprocessor
In this post, you will find the required algorithm, & 8085 program code To perform the Subtraction of two 8 bit numbers using the 8085 microprocessor. Also, you will get the observation and result.
Algorithm for Subtraction of Two 8 bit Numbers using 8085
- Start the program by loading the first data into Accumulator.
- Move the data to a register (B register).
- Get the second data and load into Accumulator.
- Subtract the two register contents.
- Check for carry.
- If carry is present take 2’s complement of Accumulator.
- Store the value of borrow in memory location.
- Store the difference value (present in Accumulator) to a memory
- location and terminate the program.
Program for Subtraction of Two 8 bit Numbers using 8085
MVI C, 00 // Initialize C to 00
LDA 4150 //Load the value to Acc.
MOV B, A //Move the content of Acc to B register.
LDA 4151 //Load the value to Acc.
SUB B
JNC LOOP //Jump on no carry.
CMA //Complement Accumulator contents.
INR A //Increment value in Accumulator.
INR C //Increment value in register C
LOOP: STA 4152 //Store the value of A-reg to memory address.
MOV A, C //Move contents of register C to Accumulator.
STA 4153 //Store the value of Accumulator memory address.
HLT //Terminate the program.
Observation
Input:
06 (4150)
02 (4251)
Output:
04 (4152)
01 (4153)
Result
Thus the 8085 microprocessor program to subtract two 8-bit numbers was executed.