S.E.Extc Sub : MPP 32 bit Muliplication PPT

Download Report

Transcript S.E.Extc Sub : MPP 32 bit Muliplication PPT

Prof.V.P.Chitragar,KGCE,Karjat
32 bit multiplication
Explanation:
First number:
12345678H
Second number: 11111111H
As one memory location can store 1 byte of data,
the above numbers will be requiring 4 memory
locations ,each i.e. 78 will be stored at SI, 56 will
be stored at (SI+1), 34 will be stored at (SI+2) and
12 will be stored at (SI+3).
1
Prof.V.P.Chitragar,KGCE,Karjat
With LEA SI,A
we are loading the starting address of number
12345678H in SI, i.e. for this 32 bit number the
least significant byte is 78 and the address for 78
is the starting address . E.g.
Address
(SI)
Data
2000
78
(SI+1) 2001
56
(SI+2) 2002
34
(SI+3) 2003
12
Lower word
of A
Higher word
of A
2
Prof.V.P.Chitragar,KGCE,Karjat
MOV AX,[SI]
This instruction will do the following:
Address
Data
(SI) 2000
(SI+1) 2001
(SI+2) 2002
(SI+2) 2003
78
56
34
12
AL
AH
78
56
1st 2 words multiplication
MUL B[BX]
The second number is pointed by register BX ,i.e.
3
Prof.V.P.Chitragar,KGCE,Karjat
BX points to the starting address of second
number B .
Address
Data
(BX) 3000
11
Lower word
of B
(BX+1) 3001
11
(BX+2) 3002
11
Higher word
of B
(BX+3) 3003
11
When MUL B[BX] is executed, the contents of AX
are multiplied by the contents of [BX] and [BX+1],
i.e. contents of 3000 and 3001 ,i.e. 5678H × 1111.
4
Prof.V.P.Chitragar,KGCE,Karjat
The result of the multiplication is stored in
i.e.
DX
AX
05C3
B5F8
As AX is used every time for arithmetic
operations, we store the contents of AX to the
memory location reserved for storing the result
of multiplication. This is done by the following
instruction:
MOV C[DI],AX
5
Prof.V.P.Chitragar,KGCE,Karjat
DI acts as a pointer for storing the result of
multiplication , e.g.
Address
(DI)
(DI+1)
(DI+2)
(DI+3)
(DI+4)
(DI+5)
(DI+6)
(DI+7)
Data
4000
4001
4002
4003
4004
4005
4006
4007
F8
B5
6
Prof.V.P.Chitragar,KGCE,Karjat
The contents of DX act as carry to be added to
the next multiplication result. DX also is used
every time for storing the higher word of the
result of multiplication of two 16 bit numbers.
Hence we store the contents of DX into CX with
MOV CX,DX
2nd 2 words multiplication
Now we multiply the higher word of A with
lower word of B, i.e. 1234H × 1111H.
7
Prof.V.P.Chitragar,KGCE,Karjat
But first, we move the higher word of A stored at
(SI+2) and (SI+3) in AL and AH respectively, by the
instruction
MOV AX,[SI+2]
i.e.
AL
34
AH
12
So the 2nd 2 words multiplication will be
executed by the instruction
MUL B[BX]
and the result will be stored in
DX
AX
0136
A974
8
Prof.V.P.Chitragar,KGCE,Karjat
Now the present contents of AX have to be
added with the previous contents of DX, which is
stored in CX i.e. A974 + 05C3 = AF37
This is done with the help of the instruction
ADD CX,AX
The result of addition are copied to the memory
location C[DI+2] and C[DI+3] with the help of the
instruction
MOV C[DI+2],CX
The higher word of multiplication i.e. 0136H,
which is stored in DX, is copied in CX with
MOV CX,DX
9
Prof.V.P.Chitragar,KGCE,Karjat
3rd 2 words multiplication
The next multiplication is between lower word
of A and higher word of B i.e.
5678H × 1111H
This is done by the instructions:
MOV AX,[SI]
MUL B[BX+2]
As we know the result of multiplication is stored
in DX:AX, the contents of AX are added to
C[DI+2] and C[DI+3] with
ADD C[DI+2],AX
i.e.
C[DI+2]=AF37+B5F8
= 1 652F
10
The higher word of multiplication result , which
is stored in DX is added with contents of CX with
ADC CX,DX
i.e.
CX=0136+05C3+1
=6FA
4th 2 words multiplication
The higher word of A ,i.e. 1234H is copied to AX
with
MOV AX,[SI+2]
This word is multiplied with the upper word of
B, i.e. 1111H with MUL B[BX+2]
The contents of AX are added to contents of CX
with
ADD CX,AX
i.e.
CX= 6FA+A974
=B06E
Prof.V.P.Chitragar,KGCE,Karjat
11
Prof.V.P.Chitragar,KGCE,Karjat
The added result stored in CX is copied to the
memory location C[DI+4] and C[DI+5] with
MOV C[DI+4],CX
Any carry generated from previous addition is
added to the present contents of DX with
ADC DX,0000H
This result in DX is copied in memory location
with
MOV C[DI+6],DX
For knowing the starting address of the result C
we use the instruction
LEA SI,C
12