8085 Program to Multiply Two 8-bit Numbers
Write an 8085 program that reads two 8-bit numbers from memory (e.g., 2500H and 2501H), multiplies them by repeated addition, and stores the 16-bit product across two bytes in memory (e.g., 3000H-3001H).
This approach is straightforward and avoids indirect multiplication or shift-based algorithms, making it easy to follow and educational.
⚡ TL;DR — Final Working Code
Section titled “⚡ TL;DR — Final Working Code” ; Interface FIRST_NUM_ADDR EQU 2500H SECOND_NUM_ADDR EQU 2501H RESULT_ADDR EQU 3000H
; Step 1: Load inputs LXI H, FIRST_NUM_ADDR MOV B, M ; B ← multiplicand INX H MOV C, M ; C ← multiplier
; Step 2: Initialize result LXI H, 0000H ; HL ← result (16-bit accumulator)
; Step 3: Multiply using repeated additionMUL_LOOP: MOV A, L ADD B MOV L, A JNC SKIP_INC INR H ; Carry to high byte
SKIP_INC: DCR C JNZ MUL_LOOP
; Step 4: Store result LXI D, RESULT_ADDR MOV M, L ; Store low byte INX D MOV M, H ; Store high byte HLT🧱 Step 1: Define the Interface and Load Inputs
Section titled “🧱 Step 1: Define the Interface and Load Inputs”First, define where your inputs come from and where the result will go:
| Address | Purpose |
|---|---|
2500H | First 8‑bit operand |
2501H | Second 8‑bit operand |
3000H | Product low byte (LSB) |
3001H | Product high byte (MSB) |
Next, begin by loading the two operands into registers for processing:
LXI H, 2500H ; HL → first operandMOV B, M ; B ← first numberINX H ; HL → second operandMOV C, M ; C ← second number🧪 Manual Test
Section titled “🧪 Manual Test”Initialize memory:
2500H = 05H2501H = 03HAfter loading:
- Register B =
05H - Register C =
03H
🧱 Step 2: Initialize Result Registers
Section titled “🧱 Step 2: Initialize Result Registers”We’ll now prepare registers to hold the result of multiplication.
Since multiplying two 8-bit numbers can produce a 16-bit result (maximum 255 × 255 = 65025 = FE01H), we need:
- One register for the low byte (e.g.,
L) - One for the high byte (e.g.,
H) - An additional register (
C) will act as a loop counter (already holds one multiplier)
🧠 What We’re Doing
Section titled “🧠 What We’re Doing”- Clear the result registers (HL pair) to start from zero
- Use
Cas the counter to add the multiplicand (B) repeatedly
🧾 Code (Initialize Result)
Section titled “🧾 Code (Initialize Result)”LXI H, 0000H ; HL ← 0000H → result = 0 ; B = multiplicand, C = multiplierNow we’re ready to perform the actual multiplication in the next step using repeated addition with carry into HL.
🧱 Step 3: Add the Multiplicand Repeatedly
Section titled “🧱 Step 3: Add the Multiplicand Repeatedly”Now we’ll perform the multiplication using repeated addition.
Since register C holds the multiplier, we’ll add the multiplicand (B) to the result (HL) that many times. To properly handle 16-bit accumulation, we’ll add B to the L register, and propagate any carry into H.
🧠 What We’re Doing
Section titled “🧠 What We’re Doing”-
Loop
Ctimes:- Add
BtoL(low byte) - If there’s a carry, increment
H(high byte)
- Add
-
Decrement
Cuntil zero
🧾 Code (Multiplication Loop)
Section titled “🧾 Code (Multiplication Loop)”MUL_LOOP: MOV A, L ; A ← current low byte ADD B ; A ← A + multiplicand MOV L, A ; Store updated low byte
JNC SKIP_INC ; If no carry, skip INR H ; Else, increment high byte
SKIP_INC: DCR C ; Decrement loop counter JNZ MUL_LOOP ; Repeat if C ≠ 0🧪 Manual Test
Section titled “🧪 Manual Test”If:
- B = 5 (multiplicand)
- C = 3 (multiplier)
Then:
- HL =
000F(15 decimal), as expected for5 × 3
Now we’re ready to store the result in memory in the next step.
🧱 Step 4: Store the 16-bit Result in Memory
Section titled “🧱 Step 4: Store the 16-bit Result in Memory”After computing the result in the HL register pair:
Lholds the lower byte of the productHholds the upper byte (in case of overflow)
Now we need to store both bytes at predefined memory addresses for output.
📦 Output Mapping
Section titled “📦 Output Mapping”| Address | Purpose |
|---|---|
3000H | Low byte of product |
3001H | High byte of product |
🧾 Code (Store Result)
Section titled “🧾 Code (Store Result)”LXI D, 3000H ; DE → destination addressMOV M, L ; Store low byte at 3000HINX H ; Move to 3001HMOV M, H ; Store high byteHLT🔍 Note: If
HLwas used earlier, use another register pair (likeDE) for storing, or reload address.
🧪 Manual Test
Section titled “🧪 Manual Test”For:
2500H = 0AH (10)2501H = 0CH (12)After execution:
3000H = 78H ; LSB = 1203001H = 00H ; MSB = 0This confirms the product 10 × 12 = 120 is stored correctly.
📚 Summary
Section titled “📚 Summary”This program multiplies two unsigned 8-bit numbers using repeated addition, a common approach on processors like the 8085 which lack a dedicated MUL instruction.
It demonstrates:
✅ Careful setup of an input/output interface ✅ Use of HL as a 16-bit accumulator ✅ Proper handling of carry across bytes ✅ Clean final result storage in memory
The method is simple, reliable, and teaches how arithmetic operations are built from basic instructions in low-level programming.