BIT151 · 2082 · 5 marks
Write an assembly language program to multiply 08H and 09H, store the product in memory location 8050H and carry in 8051H using 8085 microprocessor instructions.
Write an assembly language program to multiply 08H and 09H, store the product in memory location 8050H and carry in 8051H using 8085 microprocessor instructions. [5]
Assembly Language Program: Multiply 08H × 09H (8085 Microprocessor)
Given
- Multiplicand = 08H
- Multiplier = 09H
- Product storage address = 8050H
- Carry (higher byte) storage address = 8051H
Solution
Concept
The 8085 has no hardware multiply instruction, so multiplication is done by repeated addition: add the multiplicand (08H) to itself the number of times given by the multiplier (09H). Any carry beyond 8 bits is counted in a separate register.
Program
LXI H, 8050H ; HL points to product location 8050H
MVI B, 08H ; B = multiplicand (08H)
MVI C, 09H ; C = multiplier / counter (09H)
MVI A, 00H ; A = 00H (accumulate product low byte)
MVI D, 00H ; D = 00H (accumulate carry / high byte)
LOOP: ADD B ; A = A + B
JNC SKIP ; if no carry, skip
INR D ; else increment high byte
SKIP: DCR C ; decrement counter
JNZ LOOP ; repeat until C = 0
MOV M, A ; store product low byte at 8050H
INX H ; HL points to 8051H
MOV M, D ; store carry / high byte at 8051H
HLT ; halt
Execution Trace
| Iteration | A before | ADD B (08H) | Carry | D |
|---|---|---|---|---|
| 1 | 00H | 08H | 0 | 00H |
| 2 | 08H | 10H | 0 | 00H |
| 3 | 10H | 18H | 0 | 00H |
| 4 | 18H | 20H | 0 | 00H |
| 5 | 20H | 28H | 0 | 00H |
| 6 | 28H | 30H | 0 | 00H |
| 7 | 30H | 38H | 0 | 00H |
| 8 | 38H | 40H | 0 | 00H |
| 9 | 40H | 48H | 0 | 00H |
Verification
$$08H \times 09H = 8 \times 9 = 72_{10} = 48H$$
Since the result 72 fits in one byte (< 256), no carry is generated, so D = 00H.
Result in Memory
| Address | Content | Meaning |
|---|---|---|
| 8050H | 48H | Product (low byte) |
| 8051H | 00H | Carry (high byte) |
The final product is 48H with carry 00H.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.