File: throttle_multiply.asm

package info (click to toggle)
avra 1.2.3a-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,384 kB
  • ctags: 1,092
  • sloc: ansic: 6,329; asm: 747; pascal: 624; makefile: 82; sh: 5
file content (74 lines) | stat: -rwxr-xr-x 3,473 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;throttle_multiply.asm
;
;********************************************************************************
;* mpy8u                                                                         *
;* Second Level Subroutine                                                       *
;*                                                                               *
;* Program from Atmel file avr200.asm                                            *
;*                                                                               *
;* Since the 25kHz pwm cycle is 64 clock cycles long, this subroutine            *
;* requires just under 1 25kHz clock cycles.                                     *
;*                                                                               *
;* A single line was added which adds 3 to Cycle_count                           *
;*                                                                               *
;* Inputs:  HILOCAL1 and B_TEMPLOCAL                                             *
;*                                                                               *
;* Returns: HILOCAL1 x B_TEMPLOCAL = B_TEMPLOCAL1:B_TEMPLOCAL                    *
;*                                                                               *
;* Changed: B_TEMPLOCAL2                                                         *
;*                                                                               *
;* Calls:   Not allowed                                                          *  
;********************************************************************************

   HILOCAL1       mc8u                 ; multiplicand
   B_TEMPLOCAL    mp8u                 ; multiplier
   B_TEMPLOCAL    m8uL                 ; result Low byte
   B_TEMPLOCAL1   m8uH                 ; result High byte
   B_TEMPLOCAL2   mcnt8u               ; loop counter


;<ATMEL ROUTINE>
;***************************************************************************
;*
;* "mpy8u" - 8x8 Bit Unsigned Multiplication
;*
;* This subroutine multiplies the two register variables mp8u and mc8u.
;* The result is placed in registers m8uH, m8uL
;*  
;* Number of words   :9 + return
;* Number of cycles  :58 + return
;* Low registers used   :None
;* High registers used  :4 (mp8u,mc8u/m8uL,m8uH,mcnt8u)  
;*
;* Note: Result Low byte and the multiplier share the same register.
;* This causes the multiplier to be overwritten by the result.
;*
;***************************************************************************

;***** Subroutine Register Variables

;.def mc8u  =r16     ;multiplicand
;.def mp8u  =r17     ;multiplier
;.def m8uL  =r17     ;result Low byte
;.def m8uH  =r18     ;result High byte
;.def mcnt8u   =r19     ;loop counter

;***** Code


mpy8u:   
   clr   m8uH                          ;clear result High byte
   ldi   mcnt8u,8                      ;init loop counter
   lsr   mp8u                          ;rotate multiplier
   
m8u_1:
   brcc  m8u_2                         ;carry set 
   add   m8uH,mc8u                     ;add multiplicand to result High byte
m8u_2:
   ror   m8uH                          ;rotate right result High byte
   ror   m8uL                          ;rotate right result L byte and multiplier
   dec   mcnt8u                        ;decrement loop counter
   brne  m8u_1                         ;if not done, loop more
   ret

;<END ATMEL ROUTINE>