KEMBAR78
8085 Program To Multiply Two 8 Bit Numbers | PDF | Computer Hardware | Computer Science
0% found this document useful (0 votes)
427 views11 pages

8085 Program To Multiply Two 8 Bit Numbers

The document provides multiple 8085 assembly language programs to multiply two 8-bit numbers stored in memory, detailing algorithms, program instructions, and explanations for each approach. It discusses advantages and disadvantages of the methods, highlighting efficiency, memory usage, and error handling. The document also includes example memory addresses and expected outputs for clarity.

Uploaded by

David Talam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
427 views11 pages

8085 Program To Multiply Two 8 Bit Numbers

The document provides multiple 8085 assembly language programs to multiply two 8-bit numbers stored in memory, detailing algorithms, program instructions, and explanations for each approach. It discusses advantages and disadvantages of the methods, highlighting efficiency, memory usage, and error handling. The document also includes example memory addresses and expected outputs for clarity.

Uploaded by

David Talam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

8085 program to multiply two 8 bit numbers



Problem – Multiply two 8 bit numbers stored at address 2050 and 2051. Result is stored at address 3050
and 3051. Starting address of program is taken as 2000.

Example –

Algorithm –
1. We are taking adding the number 43 seven(7) times in this example.
2. As the multiplication of two 8 bit numbers can be maximum of 16 bits so we need register pair to
store the result.

Program –

Mnemonic
Memory Address s Comment

2000 LHLD 2050 H←2051, L←2050

2003 XCHG H↔D, L↔E

2004 MOV C, D C←D

2005 MVI D 00 D←00

2007 LXI H 0000 H←00, L←00

200A DAD D HL←HL+DE


Mnemonic
Memory Address s Comment

200B DCR C C←C-1

200C JNZ 200A If Zero Flag !=0, goto 200A

200F SHLD 3050 H→3051, L→3050

2012 HLT

Explanation – Registers used: A, H, L, C, D, E


1. LHLD 2050 loads content of 2051 in H and content of 2050 in L
2. XCHG exchanges contents of H with D and contents of L with E
3. MOV C, D copies content of D in C
4. MVI D 00 assigns 00 to D
5. LXI H 0000 assigns 00 to H and 00 to L
6. DAD D adds HL and DE and assigns the result to HL
7. DCR C decrements C by 1
8. JNZ 200A jumps program counter to 200A if zero flag != 0 (Not equal to 0)
9. SHLD stores value of H at memory location 3051 and L at 3050
10. HLT stops executing the program and halts any further execution

Another approach:
We can do multiplication of two 8-bit numbers without using DAD and XCHG command.
Program-

ADDRESS MNEMONICS COMMENT

2000 LXI H, 2050H

2003 MOV B, M B←M

2004 INX H

2005 MOV C, M C←M


2006 MVI A, 00H A←00

2008 TOP:ADD B A<-A+B

2009 DCR C C←C-1

200A JNZ TOP

200D INX H

200E MOV M, A M←A

terminate the
200F HLT
program

Explanation –Registers A, H, L, C, B are used for general purpose.


1. LXI H, 2050 will load the HL pair register with the address 2050 of memory location.
2. MOV B, M copies the content of memory into register B.
3. INX H will increment the address of HL pair by one and make it 2051H.
4. MOV C,M copies the content of memory into register C.
5. MVI A,00H assign 00 to A.
6. top: ADD B add the content of accumulator with register B and store the result in accumulator.
7. DCR C decrement the register C.
8. JNZ TOP jumps on top till C doesn’t becomes 0.
9. INX H will increment the address of HL pair by one and make it 2052H.
10. MOV M,A copies the content of A which is our answer to register M.
11. HLT stops executing the program and halts any further execution.

Advantages:

 The program is a simple and efficient way to multiply two 8-bit numbers using the 8085
microprocessor.

 The program uses only a few instructions and requires minimal memory space, making it easy to
implement in a microcontroller.

 The program produces accurate results since it performs a series of repetitive additions to calculate
the product.

 The program can be easily modified to multiply larger or smaller numbers by changing the memory
addresses.

Disadvantages:
 The program is computationally intensive and time-consuming since it requires a series of repetitive
additions to calculate the product.

 The program is not very efficient in terms of memory usage since it requires several registers to store
the operands and intermediate results.

 The program is not very scalable since it requires a large number of iterations to multiply large
numbers, which may cause overflow or underflow conditions.

 The program does not provide any error checking or reporting mechanism, which may make it
difficult to identify errors or faults in the program.

8085 program to multiply two 8 bit numbers


MicrocontrollerMicroprocessor8085

In this program we will see how to multiply two 8-bit numbers using 8085 microprocessor.

Problem Statement

Write 8085 Assembly language program to multiply two 8-bit numbers stored in memory location and
store the 16-bit results into the memory.

Discussion

The 8085 has no multiplication operation. To get the result of multiplication, we should use the repetitive
addition method.

After multiplying two 8-bit numbers it may generate 1-byte or 2-byte numbers, so we are using two
registers to hold the result.

We are saving the data at location 8000H and 8001H. The result is storing at location 8050H and 8051H.

Input

Address Data

. .
. .
. .

8000 DC
Address Data

8001 AC

. .
. .
. .

Flow Diagram

Program
Address HEX Codes Labels Mnemonics Comments

F000 21, 00, 80 LXI H,8000H Load first operand address

F003 46 MOV B, M Store first operand to B

F004 23 INX H Increase HL pair

F005 AF XRA A Clear accumulator

F006 4F MOV C, A Store 00H at register C

F007 86 LOOP ADD M Add memory element with Acc

F008 D2, 0C, F0 JNC SKIP When Carry flag is 0, skip next task

F00B 0C INR C Increase C when carry is 1

F00C 05 SKIP DCR B Decrease B register

F00D C2, 07, F0 JNZ LOOP Jump to loop when Z flag is not 1

F010 21, 50, 80 LXI H,8050H Load Destination address

F013 71 MOV M, C Store C register content into memory

F014 23 INX H Increase HL Pair

F015 77 MOV M, A Store Acc content to memory

F016 76 HLT Terminate the program

Output

Address Data

. .
. .
. .

8050 93

8051 D0

.
.
.

8085 program to multiply two 8 bit numbers using logical instructions




Problem – Write a assembly language program multiply two 8 bit numbers and store the result at
memory address 3050 in 8085 microprocessor. Example –

The value of accumulator(A) after using RLC instruction is:


A = 2n*A
Where n = number of times RLC instruction is used. Assumptions – Assume that the first number is
stored at register B, and second number is stored at register C. And the result must not have any
carry. Algorithm –
1. Assign the value 05 to register B
2. Assign the value 04 to register C
3. Move the content of B in A
4. Rotate accumulator left without carry
5. Rotate accumulator left without carry
6. Store the content of accumulator at memory address 3050
7. Halt of the program
Program –
MEMORY
ADDRESS MNEMONICS COMMENTS

2000 MVI B 05 B <- 05

2002 MVI C 04 C <- 04

2004 MOV A, B A <- B

2005 RLC rotate the content of A without carry


MEMORY
ADDRESS MNEMONICS COMMENTS

2006 RLC rotate the content of A without carry

2007 STA 3050 3050 <- A

200A HLT End of the program

Explanation –
1. MVI B 05: assign the value 05 to B register.
2. MVI C 04: assign the value 04 to C register.
3. MOV A, B: move the content of register B to register A.
4. RLC: rotate the content of accumulator left without carry.
5. RLC: rotate the content of accumulator left without carry.
6. STA 3050: store the content of register A at memory location 3050
7. HLT: stops the execution of the program.

Advantages:

 The program is simple and easy to understand since it only uses a few instructions.

 The program uses only logical instructions to perform the multiplication operation, which reduces the
number of registers required.

 The program produces accurate results since it performs a series of bitwise operations to calculate the
product.

Disadvantages:

 The program is computationally intensive and time-consuming since it requires several instructions to
perform the multiplication operation.

 The program is not very efficient in terms of memory usage since it requires several registers to store
the operands and intermediate results.

 The program is not very scalable since it requires a large number of iterations to multiply large
numbers, which may cause overflow or underflow conditions.

 The program does not handle overflow or underflow conditions, which may occur if the product of
the two numbers is greater than 255.

 The program does not provide any error checking or reporting mechanism, which may make it
difficult to identify errors or faults in the program.
8085 Program to multiply two 8-
bit numbers using shifting
multiplicand
8085 is a Microprocessor which was developed by Intel in 1970s. All the
instructions in this microprocessor are encoded in a single byte. Some of the
instructions are followed by one or two bytes of data, which can be a memory
address, an immediate operand or a port number.

In this post, we will write a program in 8085 to multiply two 8-bit numbers using
shifting multiplicand.

Algorithm

Start
Read multiplier
Read multiplicand
Extend multiplicand to double(16-bit)
prod <- 0
count <- 8
Right shift multiplier
If CS == 0 go to 10
prod <- prod + multiplicand
multiplicand <- multiplicand x 2 (Left shift multiplicand)
count <- count - 1
If count != 0 go to 7
Store prod
Stop

Flow Chart
Program

LHLD 2100H
MOV A, L
MOV E, H
MVI D, 00H
LXI H, 0000H
MVI C, 08H
BACK: RAR
JNC NEXT
DAD D
NEXT: XCHG
DCR C
JNZ BACK
SHLD 2102H
RST-5

Example

2100H: 02
2101H: 03
2102H: 06 -> Output

You might also like