Experiment-3: Write a program to perform: i. Subtraction of two 8 bit numbers without borrows. ii. Subtraction of two 8 bit numbers with borrows.
Objective:
To understand the assembly program
To draw flowchart for subtraction of two numbers
To develop the assembly program for subtraction
To analyse the program and interpret errors and result
Requirement:
Operating System – Windows, Linux
- 8085 Simulator
ALGORITHM
Data variable
Variable | Address | Value | Address | Value |
X: | 4200 | 25 | 4201 | 15 |
Y: | 4203 | 12 | 4204 | 05 |
Z: | 4205 | 4206 |
Algorithm:
- Load source (X) address in HL pair
- Load source (Y) address in DE pair
- Load Accumulator (A) from memory i.e [HL]
- Swap HL and DE pair HL ßàDE
- Load register B from memory [HL]
- Subtract A-B
- Save result in register C
- Increment HL
- Swap HL with DE HL ßàDE
- Increment HL
- Load accumulator from memory address 4201 [HL]
- Swap HL and DE
- Load register B from memory
- Subtract with borrow
- Increment HL to save the result
- Save register C (least significant result) at 4205 [HL] ß C
- Increment HL now 4206
- Save most significant digit of result in memory 4206 [HL] ß A
- stop
Program in assembly with OPCODEs
Address | OP-CODE /DATA | Label | Mnemonic | Comments |
C9 09 042 | JMP start | |||
4200 | 19 0F | X: | DB 25, 15 | |
4203 | 0C 05 | Y: | DB 12, 05 | |
4205 | Z: | DB 00, 00 | ||
4209 | 00 | Start: | nop | |
420A | 21 03 042 | LXI H,X | Initialize memory pointer in HL | |
420D | 11 05 042 | LXI D,Y | Initialize memory pointer in DE | |
4210 | 7E | MOV A, M | ACC = [HL] | |
4211 | EB | XCHG | HL ßàDE
|
|
4212 | 46 | MOV B, M | B ß [hl] | |
4213 | 90 | SUB B | A = A-B | |
4214 | 4F | MOV C, A | C=A | |
4215 | 23 | INX H | HL++ | |
4216 | EB | XCHG | HL ßàDE | |
4217 | 23 | INX H | HL++ | |
4218 | 7E | MOV A, M | ACC = [HL] | |
4219 | EB | XCHG | HL ßàDE | |
421A | 46 | MOV B, M | B = [HL] | |
421B | 98 | SBB B | A = A-B-1 | |
421C | 23 | INX H | HL++ | |
421D | 71 | MOV M,C | [HL] = C | |
421E | 23 | INX H | HL++ | |
421F | 77 | MOV M,A | [HL] = A | |
4220 | 76 | HLT | end |
Result:
Viva Questions:
Que-1: How is subtraction performed in computer.
Ans:
Subtraction is performed by using 2’s complement arithmetic.
Que-2: What are the commands available in 8085 microprocessor for performing subtraction
Ans:
- SUB – Subtraction
- SBB – subtraction with borrow