Tuesday, 25 February 2014

16 bit multiplication program in 8051

This is 16 bit multiplication program in assembly language in 8051 micro controller with easiest algorithm. Each number is divided in two 8 bit words and they are called MSB1,LSB1 and MSB2,LSB2.

Suppose we have two hex numbers "ABCD" & "EFGH". Here each alphabet is 4 bit binary number. In 8051 we can multiply 8 bit numbers using MUL instruction.

Here AB = MSB1 (most significant 4 bits of 1st number)
         CD = LSB1 (least significant 4 bits of 1st number)
         EF = MSB2 (most significant 4 bits of 2nd number)
         GH = LSB2 (least significant 4 bits of 2nd number)


MOV R1,MSB1
MOV R2,MSB2
MOV R3,LSB1
MOV R4,LSB2

MOV A,R3
MOV B,R4
MUL AB
MOV 20H,A
MOV 21H,B

MOV A,R3
MOV B R2
MUL AB
MOV 22H,B
ADDC A,21H
MOV 21H,A

MOV A,R1
MOV B,R4
MUL AB
ADDC A,21H
MOV 21H,A
MOV A,B
ADDC A,22H
MOV 22H,A

MOV A,R1
MOV B,R2
MUL AB
ADDC A,22H
MO 22H,A
MOV A,B
ADDC A,#00H
MOV 23H,A


The answer would be in following address, (23H 22H 21H 20H).

Ex. - You have two 16 bit Hex number. FFFF & EF9D.

So here,

AB = FF(In Hex)
CD = FF(In Hex)
EF = EF (In Hex)
GH = 9D (In Hex)

After simulating this program with following values, you will find following values in below mention addresses,

On 23H address values is EF (In Hex).
On 22H address values is 9C (In Hex).
On 21H address values is 10 (In Hex).
On 20H address values is 63 (In Hex).

So your answer would be EF9C1063 (In Hex).

If you find any quarry, feel free to comment.

https://pythonhighschool.wordpress.com/2014/02/26/16-bit-multiplication-program-in-8051/

10 comments:

  1. This is great. Makes more sense.

    ReplyDelete
  2. Write an assembly language program that implements the
    multiplication of two 16-bit unsigned integers. (The operands
    are in registers R0-R1 and R2-R3 respectively. The routine
    should return the 32-bit result in R0-R1-R2-R3
    for this program what kind of modifications need to be done ? please reply sir

    ReplyDelete
  3. It is the same code by replacing R1 by R0, R2 by R1, R3 by R2 and R4 by R3. After fetching answer from address (20H-23H) you can move respective data to R0,R1,R2 and R3.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Really makes more sense than what I was told at class

    ReplyDelete
  6. Thanks it was easy to understand how to do a 16 bit × 8 bit multiplication in 8051👍

    ReplyDelete
  7. Write an Assembly Language Program to multiply two 16-bit unsigned numbers at internal RAM locations 30H, 31H and 32H,33H and place the 16-bit result at locations 34H,35H.

    ReplyDelete

View My Stats