Past exam question: 2082 Kartik (Back), Q3
Open in the Padhaiko appQuestion
Write a program in 8085 to multiply two 8 bit binary numbers stored at 2050H and 2051H where multiplicand is at 2050H and multiplier is at 2051H. Store 16 bit result at memory location 2052H.
Solution
Algorithm & Repeated Addition Design:
- Multiplicand is at
2050H, Multiplier is at2051H. - Product of two 8-bit numbers can be up to 16 bits wide (
FFH * FFH = FE01H). - Because 8085 lacks a hardware multiplication opcode, multiplication is performed by repeated addition:
- Load the multiplier into counter register C.
- If multiplier is 0, the product is immediately
0000H. - Load the 8-bit multiplicand into register E, and clear D (
DE = 00[Multiplicand]). - Initialize product accumulator
HL = 0000H. - In a loop, add
DEtoHLusing 16-bit double addition (DAD D). - Decrement counter C (
DCR C) and repeat until C reaches 0. - Store the 16-bit result in
HLto memory locations2052H(low byte) and2053H(high byte) usingSHLD 2052H.
8085 Assembly Language Program:
LDA 2051H ; Load multiplier into accumulator
MOV C, A ; C = multiplier (loop counter)
ORA A ; Test if multiplier is zero
JZ STORE_ZERO ; If multiplier is 0, product is 0
LDA 2050H ; Load multiplicand into accumulator
MOV E, A ; E = multiplicand
MVI D, 00H ; D = 00H (DE = 16-bit multiplicand)
LXI H, 0000H ; HL = 0000H (16-bit product accumulator)
MULT_LOOP:
DAD D ; HL = HL + DE (add multiplicand)
DCR C ; Decrement loop counter
JNZ MULT_LOOP ; Repeat until counter reaches 0
JMP STORE_RES
STORE_ZERO:
LXI H, 0000H ; Result is zero
STORE_RES:
SHLD 2052H ; Store lower byte at 2052H, higher byte at 2053H
HLT ; Terminate programTrace Example:
- Multiplicand at
2050H=05H(5 in decimal). - Multiplier at
2051H=04H(4 in decimal). - Initial:
HL = 0000H,DE = 0005H,C = 04H.- Iteration 1:
HL = 0000H + 0005H = 0005H,C = 03H - Iteration 2:
HL = 0005H + 0005H = 000AH,C = 02H - Iteration 3:
HL = 000AH + 0005H = 000FH,C = 01H - Iteration 4:
HL = 000FH + 0005H = 0014H,C = 00H(Loop ends)
- Iteration 1:
- Store result:
[2052H] = 14H(20 decimal),[2053H] = 00H.
Answer:
The program performs repeated addition by adding the 16-bit extended multiplicand in DE to HL using DAD D for multiplier times (counter C), then saves the 16-bit product to 2052H and 2053H using SHLD 2052H.