1 | ;***************************************************************************
|
2 | ;*
|
3 | ;* "mpy16u" - 16x16 Bit Unsigned Multiplication
|
4 | ;*
|
5 | ;* This subroutine multiplies the two 16-bit register variables
|
6 | ;* mp16uH:mp16uL and mc16uH:mc16uL.
|
7 | ;* The result is placed in m16u3:m16u2:m16u1:m16u0.
|
8 | ;*
|
9 | ;* Number of words :14 + return
|
10 | ;* Number of cycles :153 + return
|
11 | ;* Low registers used :None
|
12 | ;* High registers used :7 (mp16uL,mp16uH,mc16uL/m16u0,mc16uH/m16u1,m16u2,
|
13 | ;* m16u3,mcnt16u)
|
14 | ;*
|
15 | ;***************************************************************************
|
16 |
|
17 | ;***** Subroutine Register Variables
|
18 |
|
19 | .def mc16uL =r16 ;multiplicand low byte
|
20 | .def mc16uH =r17 ;multiplicand high byte
|
21 | .def mp16uL =r18 ;multiplier low byte
|
22 | .def mp16uH =r19 ;multiplier high byte
|
23 | .def m16u0 =r18 ;result byte 0 (LSB)
|
24 | .def m16u1 =r19 ;result byte 1
|
25 | .def m16u2 =r20 ;result byte 2
|
26 | .def m16u3 =r21 ;result byte 3 (MSB)
|
27 | .def mcnt16u =r22 ;loop counter
|
28 |
|
29 | ;***** Code
|
30 |
|
31 | mpy16u: clr m16u3 ;clear 2 highest bytes of result
|
32 | clr m16u2
|
33 | ldi mcnt16u,16 ;init loop counter
|
34 | lsr mp16uH
|
35 | ror mp16uL
|
36 |
|
37 | m16u_1: brcc noad8 ;if bit 0 of multiplier set
|
38 | add m16u2,mc16uL ;add multiplicand Low to byte 2 of res
|
39 | adc m16u3,mc16uH ;add multiplicand high to byte 3 of res
|
40 | noad8: ror m16u3 ;shift right result byte 3
|
41 | ror m16u2 ;rotate right result byte 2
|
42 | ror m16u1 ;rotate result byte 1 and multiplier High
|
43 | ror m16u0 ;rotate result byte 0 and multiplier Low
|
44 | dec mcnt16u ;decrement loop counter
|
45 | brne m16u_1 ;if not done, loop more
|
46 | ret
|