Wednesday, October 21, 2015

8085 Program To Multiply Two 8 Bit Numbers

Let us suppose that we store the two 8 bit numbers that are to be multiplied in the memory location 9000H and 9001H. Now the product of these numbers is to be stored in 9002H and the carry is to be stored in 9003H.

Algorithm:

  1. Start
  2. Initialize register C with 00.
  3. Load into accumulator directly from location 9000H.
  4. Move content of A into register B.
  5. Load into accumulator directly from 9001H.
  6. Move content of accumulator A into register D.
  7. Move 00 data into accumulator A.
  8. Add register B with accumulator A.
  9. If carry is present goto 10 else goto 11.
  10. Increment register C by 1.
  11. Decrement register D by 1.
  12. If zero is present in the accumulator then goto 13 else goto 8.
  13. Store from accumulator into memory location 9002H.
  14. Move contents of register C into accumulator.
  15. Store content present in accumulator to address 9003H.
  16. Terminate the program.

Program Code:

MVI C, 00H
LDA 9000H
MOV B, A
LDA 9001H
MOV D, A
MVI A, 00H
UP:
ADD B
JNC DOWN
INR C
DOWN:
DCR D
JNZ UP
STA 9002H
MOV A, C
STA 9003H
HLT

Firstly, value 00 is moved into register C to count the carry. The first 8 bit number stored in memory location 9000H is then loaded into the accumulator which is again moved into register B. The second 8 bit number stored in memory location 9001H in now moved in to accumulator which is again moved into register D. So the two numbers that are to be multiplied are now in registers B and D. Since 8085 does not have instruction for multiplication so we repetitive addition for multiplication (this means that to multiply 5 and 3, we either add 5 three times or we add 3 five times with itself). We move 00 into accumulator A so that garbage values are not added. Now, we repeatedly add the content of one register with itself and the content of other register is used as a counter. So we add the contents of register B with the contents of accumulator and the result is stored in accumulator. If carry is present we increment register C by 1, if not then we skip the increment instruction and we decrease the content of register D by 1. We repeatedly add contents of register B until the content of register D is 0. The result (which is in accumulator) is stored into memory location 9002H and the carry in moved from register C to accumulator A and then stored into memory location 9003H.

Output:

Example 1

Here, 5 and 3 are multiplied and their product is 15 which is 0F in Hexadecimal and is stored in 9002H. Since no carry is generated so 9003H has 00 stored in it.

Example 2


Here, 10 and 10 are multiplied as:
   10
X10
-----
100

So the carry value is 1 and the product value is 100 so 00 is stored in memory location 9002H and the carry i.e. 01 is stored in 9003H.

6 comments: