Open In App

8085 program to multiply two 16-bit numbers

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Problem: Write an assembly language program in 8085 microprocessor to multiply two 16 bit numbers. 

Assumption:

  • The starting address of program: 2000 
  • Input memory location: 2050, 2051, 2052, 2053 
  • Output memory location: 2054, 2055, 2056, 2057 

Example:

INPUT:
       (2050H) = 04H
       (2051H) = 07H 
       (2052H) = 02H 
       (2053H) = 01H
OUTPUT:
        (2054H) = 08H
        (2055H) = 12H
        (2056H) = 07H
        (2057H) = O0H

Result:  Hence we have multiplied two 16-bit numbers. 

Algorithm:

  1. Load the first data in the HL pair. 
  2. Move content of HL pair to the stack pointer. 
  3. Load the second data in the HL pair and move it to DE. 
  4. Make H register as 00H and L register as 00H. 
  5. ADD HL pair and stack pointer. 
  6. Check for carrying if carry increment it by 1 else moves to the next step. 
  7. Then move E to A and perform OR operation with accumulator and register D. 
  8. If the value of the operation is zero, then store the value else go to step 3. 

Program:

MEMORY ADDRESS MNEMONICS COMMENTS
2000 LHLD 2050 Load H-L pair with data of address 2050 and 2051
2003 SPHL SAVE IT IN STACK POINTER
2004 LHLD 2052 Load H-L pair with data of address 2052 and 2053
2007 XCHG EXCHANGE HL AND DE PAIR CONTENT
2008 LXI H,0000H H<-00H,L<-00H
200B LXI B,0000H B<-00H,C<-00H
200E DAD SP  
200F JNC 2013 JUMP NOT CARRY
2012 INX B INCREMENT BC BY 1
2013 DCX D DECREMENT DE BY 1
2014 MOV A,E A<-E
2015 ORA D OR THE CONTENT OF ACCUMULATOR AND D REGISTER
2016 JNZ 200E JUMP NOT ZERO
2019 SHLD 2054 L<-2054,H<-2055
201C MOV L,C L<-C
201D MOV H,B B<H
201E SHLD 2056 L<-2055,H<-2056
2021 HLT TERMINATES THE PROGRAM

 

Explanation: 

Registers B, C, D, E, H, L, and accumulator are used for general purposes. 

  1. LHLD 2050: load HL pair with data of address 2050and 2051. 
     
  2. SPHL: save the content of HL in the stack pointer. 
     
  3. LHLD 2052: load H-L pair with data of addresses 2052 and 2053. 
     
  4. XCHG: exchange the content of the HL pair with DE. 
     
  5. LXI H, 0000H: make H as 00H and L as 00H. 
     
  6. LXI B, 0000H: make B as 00h and C as 00H 
     
  7. DAD SP: ADD HL pair and stack pointer. 
     
  8. JNC 2013: jump to address 2013 if there will be no carry. 
     
  9. INX B: increments BC register with 1. 
     
  10. DCX D: decrements DE register pair by 1. 
     
  11. MOV A, E: move the content of register E to the accumulator. 
     
  12. ORA D: or the content of accumulator and D register. 
     
  13. JNZ 200E: jump to address 200E if there will be no zero. 
     
  14. SHLD 2054: store the result to memory addresses 2054 and 2055 from HL pair register. 
     
  15. MOV L, C: move the content of register C to L. 
     
  16. MOV H, B: move the content of register B to H. 
     
  17. SHLD 2056: store the result to memory addresses 2056 and 2057 from HL pair register. 
     
  18. HLT: terminates the program. 

Disadvantages:

  • This program uses a loop to perform the multiplication operation, which can be slow for large inputs.
     
  • The program assumes that the input numbers are both positive and within the range of 16 bits, which may not always be the case.
     
  • The program does not handle overflow situations, where the result of the multiplication operation is larger than 16 bits.
     
  • The program assumes that the memory locations of the 16-bit numbers are known and fixed, which may not always be the case in a dynamic computing environment.
     
  • The program is complex and difficult to understand, making it difficult to modify or debug.

Similar Reads

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 - We are taking adding the number 43 seven(7) times in this example.As the multiplication of two 8 bit numbers can be maximum of 16 bits so we need register pair to store
3 min read
8085 program to multiply two 8 bit numbers using logical instructions
Prerequisite - Logical instructions in 8085 microprocessor 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 t
2 min read
8085 program to find maximum of two 8 bit numbers
Problem - Write a assembly language program to find maximum of two 8 bit numbers in 8085 microprocessor. Assumptions - Starting memory locations and output memory locations are 2050, 2051 and 3050 respectively. Example - Algorithm - Load value in the accumulator Then, copy the value to any of the register Load next value in the accumulator Compare
1 min read
8085 program to add two 8 bit numbers
Problem - Write an assembly language program to add two 8 bit numbers stored at address 2050 and address 2051 in 8085 microprocessor. The starting address of the program is taken as 2000. Example - Algorithm - Load the first number from memory location 2050 to accumulator.Move the content of accumulator to register H.Load the second number from mem
2 min read
8085 program to add two 16 bit numbers
Problem: Write an assembly language program to add two 16 bit numbers by using: 8-bit operation16-bit operation Example: 1. Addition of 16-bit numbers using 8-bit operation: It is a lengthy method and requires more memory as compared to the 16-bit operation. Algorithm: Load the lower part of the first number in the B register.Load the lower part of
3 min read
8085 program to swap two 8-bit numbers
Problem: Write an assembly language program to swap two 8-bit numbers stored in an 8085 microprocessor. Assumption: Suppose there are two 8-bit numbers. One 8-bit number is stored at location 2500 memory address and another is stored at location 2501 memory address. Let 05 be stored at location 2500 and 06 be stored at location 2501 (not necessaril
4 min read
8085 program to subtract two 8-bit numbers with or without borrow
Problem – Write a program to subtract two 8-bit numbers with or without borrow where first number is at 2500 memory address and second number is at 2501 memory address and store the result into 2502 and borrow into 2503 memory address. Example – Algorithm – Load 00 in a register C (for borrow)Load two 8-bit number from memory into registersMove one
3 min read
8085 program to find larger of two 8 bit numbers
Problem - Write a program in 8085 microprocessor to find out larger of two 8-bit numbers, where numbers are stored in memory address 2050 and 2051, and store the result into memory address 3050. Example - Algorithm - Load two numbers from memory 2050 &amp; 2051 to register L and H .Move one number(H) to Accumulator A and subtract other number(L) fr
3 min read
8085 program to swap two 16 bit numbers using Direct addressing mode
Problem - Write a program to swap two 16-bit numbers using direct addressing mode where starting address is 2000 and the first 16-bit number is stored at 3000 and the second 16-bit number is stored at 3002 memory address. Example – Algorithm – Load a 16-bit number from memory 3000 into a register pair (H-L)Exchange the register pairsLoad a 16-bit n
2 min read
8085 program to swap two 8 bit numbers using Direct addressing mode
Problem - Write a program to swap two 8-bit numbers using direct addressing mode where starting address is 2000 and the first 8-bit number is stored at 3000 and the second 8-bit number is stored at 3001 memory address. Example – Algorithm – Load a 8-bit number from memory 3000 into accumulatorMove value of accumulator into register HLoad a 8-bit nu
2 min read