Multiplication Programs in 8085 Microprocessor

In the article, there are few examples of multiplication programs in8085 microprocessorin assembly language programming (ALP). You need to learn the instruction set of 8085 in detail before programming.

One program can be performed in multiple ways. Here they are mentioned as Program 1, Program 2 … Comments in each program is written after semicolon (;).

Multiplication Programs in 8085 Microprocessor

Multiplication of two 8 bit numbers in 8085 microprocessor

Multiply two 8-bit numbers stored in memory locations 2200H and 2201H by repetitive addition and store the result in memory locations 2202H and 2203H.

Multiplication Programs in 8085 Microprocessor

Program 1:

LDA 2200H ; Copy the contents from memory location 2200H to accumulator

MOV E, A ; Copy accumulator to register E

MVI D, 00H ; Get the first number in DE register pair

LDA 2201H ; Copy the contents from memory location 2201H to accumulator

MOV C, A ; Initialize counter by value of multiplier

LXI H, 0000H ; Result = 0

BACK:DAD D ; Result = result + first number

DCR C ; Decrement counter

JNZ BACK ; If count≠0 (i.e. Zero flag≠0) repeat the loop

SHLD 2202H ; Store value of H at memory location 2202H and L at 2203H

HLT ; Terminate program execution.

Program 2:

LHLD 2200H ; Loads content of 2200H in H and content of 2201H in L

XCHG ; Exchange contents of H with D and contents of L with E

MOV C, D ; Copy contents of register D in C

MVI D, 00H ; Copy 00H into register D

LXI H, 0000H ; assigns 00 to H and 00 to L

BACK:DAD D ; Result = result + first number

DCR C ; Decrement counter

JNZ BACK ; If count≠0 (i.e. Zero flag≠0) repeat the loop

SHLD 2202H ; stores value of H at memory location 2203 and L at 2202

HLT ; Terminate program execution.

Sample Example:

(2200H) = 03H

(2201H) = B2H

Result = B2H + B2H + B2H = 216H

= 216H

(2202H) = 16H

(2203H) = 02H

Above two programs generate 16-bit result and stores it onto successive memory location. Multiple times addition can be performed using ADD instruction as follows which is useful for 8-bit result only.

Program 3:

LXI H, 2200H ; H-L register pair is loaded with 2200H

MOV B, M ; Copy the contents of memory 2200H into register B

INX H ; Increment the address of HL pair by one and make it 2201H

MOV C, M ; Copy the content of memory into register C (Get second number)

MVI A, 00H ; Assign 00H to accumulator.

BACK:ADD B ; Add the content of accumulator with register B and store the result in accumulator.

DCR C ; Decrement the register C (counter)

JNZ BACK ; If count≠0 (i.e. Zero flag≠0) repeat the loop

INX H ; Increment the address of HL pair by one and make it 2202H

MOV M, A ; Copy the content of accumulator (answer) to register M.

HLT ; Terminate program execution.

Sample Example 1:

(2200H) = 15H

(2201H) = 08H

Result = (2202H) = A8H

This is the correct answer.

Sample Example 2:

(2200H) = 15H

(2201H) = A2H

Result = (2202H) = 4AH

Note that, the answer for above calculation (sample example 2) should be D4AH but it will only show A2H because accumulator can only save data of 8-bit. Hence for the numbers generating 16-bit answer above program will show incomplete (/wrong) answer.

multiplication of two BCD numbers in 8085

Write an assembly language program to multiply 2 BCD numbers

Program:

MVI C, Multiplier ; Load BCD multiplier

MVI B 00 ; Initialize counter

LXI H, 0000H ; Result = 0000

MVI E, multiplicand ; Load multiplicand

MVI D 00H ; Extend to 16-bits

BACK: DAD D ; Result = Result + Multiplicand

MOV A, L ; Get the lower byte of the result

ADI 00H

DAA ; Adjust the lower byte of result to BCD.

MOV L, A ; Store the lower byte of result

MOV A, H ; Get the higher byte of the result

ACI 00H

DAA ; Adjust the higher byte of the result to BCD

MOV H, A ; Store the higher byte of result.

MOV A, B ; [Increment

ADI 01H ; counter

DAA ; adjust it to BCD and

MOV B, A ; store it]

CMP C ; Compare if count = multiplier

JNZ BACK ; if not equal repeat

HLT ; Stop

Recent posts

Leave a Comment

Your email address will not be published. Required fields are marked *