8085 program to multiply two 16-bit numbers
Problem: Write an assembly language program in 8085 microprocessor to multiply two 16 bit numbers.
- The starting address of program: 2000
- Input memory location: 2050, 2051, 2052, 2053
- Output memory location: 2054, 2055, 2056, 2057
(2050H) = 04H
(2051H) = 07H
(2052H) = 02H
(2053H) = 01H
(2054H) = 08H
(2055H) = 12H
(2056H) = 07H
(2057H) = O0H
Result: Hence we have multiplied two 16-bit numbers.
- Load the first data in the HL pair.
- Move content of HL pair to the stack pointer.
- Load the second data in the HL pair and move it to DE.
- Make H register as 00H and L register as 00H.
- ADD HL pair and stack pointer.
- Check for carrying if carry increment it by 1 else moves to the next step.
- Then move E to A and perform OR operation with accumulator and register D.
- If the value of the operation is zero, then store the value else go to step 3.
||Load H-L pair with data of address 2050 and 2051
||SAVE IT IN STACK POINTER
||Load H-L pair with data of address 2052 and 2053
||EXCHANGE HL AND DE PAIR CONTENT
||JUMP NOT CARRY
||INCREMENT BC BY 1
||DECREMENT DE BY 1
||OR THE CONTENT OF ACCUMULATOR AND D REGISTER
||JUMP NOT ZERO
||TERMINATES THE PROGRAM
Registers B, C, D, E, H, L, and accumulator are used for general purposes.
- LHLD 2050: load HL pair with data of address 2050and 2051.
- SPHL: save the content of HL in the stack pointer.
- LHLD 2052: load H-L pair with data of addresses 2052 and 2053.
- XCHG: exchange the content of the HL pair with DE.
- LXI H, 0000H: make H as 00H and L as 00H.
- LXI B, 0000H: make B as 00h and C as 00H
- DAD SP: ADD HL pair and stack pointer.
- JNC 2013: jump to address 2013 if there will be no carry.
- INX B: increments BC register with 1.
- DCX D: decrements DE register pair by 1.
- MOV A, E: move the content of register E to the accumulator.
- ORA D: or the content of accumulator and D register.
- JNZ 200E: jump to address 200E if there will be no zero.
- SHLD 2054: store the result to memory addresses 2054 and 2055 from HL pair register.
- MOV L, C: move the content of register C to L.
- MOV H, B: move the content of register B to H.
- SHLD 2056: store the result to memory addresses 2056 and 2057 from HL pair register.
- HLT: terminates the program.
- 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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!