Section: Arithmetic & Logic Operations
Aim: To subtract two 8 bit numbers stored at consecutive memory locations and also to verify the result.
Apparatus Required: 8085 microprocessor kit, key board.
Algorithm:
- Initialize memory pointer to data location.
- Get the first number from memory in accumulator.
- Get the second number and subtract from the accumulator.
- If the result yields a borrow, the content of the acc. is complemented and 01H is added to it (2’s complement). A register is cleared and the content of that reg. is incremented in case there is a borrow. If there is no borrow the content of the acc. is directly taken as the result.
- Store the answer at next memory location.
Program:
| Address | Label | Mnemonics | Operand | Comment |
|---|---|---|---|---|
| 4100 | START | MVI | C, 00 | Clear C reg. |
| 4102 | LXI | H, 4200 | Initialize HL reg. to 4500 | |
| 4105 | MOV | A, M | Transfer first data to accumulator | |
| 4106 | INX | H | Increment HL reg. to point next mem. Location. | |
| 4107 | SUB | M | Subtract first number from acc. Content. | |
| 4108 | JNC | L1 | Jump to location if result does not yield borrow. | |
| 410B | INR | C | Increment C reg. | |
| 410C | CMA | Complement the Acc. Content | ||
| 410D | ADI | 01H | Add 01H to content of acc. | |
| 410F | L1 | INX | H | Increment HL reg. to point next mem. Location. |
| 4110 | MOV | M, A | Transfer the result from acc. to memory. | |
| 4111 | INX | H | Increment HL reg. to point next mem. Location. | |
| 4112 | MOV | M, C | Move carry to mem. | |
| 4113 | HLT | Stop the program |
Observation:
- Input:
- Address
4200:04 - Address
4201:01
- Address
- Output:
- Address
4202:03 - Address
4203:00
- Address
Result: Thus the 8-bit numbers stored at 4200 & 4201 are subtracted and the result is stored at 4202 & 4203.
Flowchart:
+-------------------+
| START |
+---------+---------+
|
v
+-------------------+
| [C] <- 00H |
+---------+---------+
|
v
+-------------------+
| [HL] <- 4200H |
+---------+---------+
|
v
+-------------------+
| [A] <- [M] |
+---------+---------+
|
v
+-------------------+
| [HL] <- [HL] + 1 |
+---------+---------+
|
v
+-------------------+
| [A] <- [A] - [M] |
+---------+---------+
|
v
/ \
/ Is \
/ there a \
< Borrow? >
\ /
\ /
\ /
|
+-----------+-----------+
| |
YES NO
| |
v |
+-------------------+ |
| Complement [A] | |
| Add 01H to [A] | |
+---------+---------+ |
| |
v |
+-------------------+ |
| [C] <- [C] + 1 | |
+---------+---------+ |
| |
+-----------+-----------+
|
v
+-------------------+
| [HL] <- [HL] + 1 |
+---------+---------+
|
v
+-------------------+
| [M] <- [A] |
+---------+---------+
|
v
+-------------------+
| [HL] <- [HL] + 1 |
+---------+---------+
|
v
+-------------------+
| [M] <- [C] |
+---------+---------+
|
v
+-------------------+
| STOP |
+-------------------+
Viva Questions:
- What is meant by ADI instruction?
- What is an instruction?
- What is Mnemonic?
- What is the purpose of CMA instruction?
- What is the function of stack pointer?
- Why ADI 01H is used in two’s complement of an 8-bit number?
- How many memory locations can be addressed by a microprocessor with 14 address lines?
For all 2026 published articles list: click here:
…till the next post, bye-bye & take care