⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mul_q.asm

📁 TI的digital motor control lib的源代码。了解TI的编程规范
💻 ASM
字号:
;=====================================================================================
; File name:        MUL_Q.ASM                     
;                    
; Originator:	Digital Control Systems Group
;			Texas Instruments
;
; Description:                                 
; Multiplication of two numbers in arbitraty Q system
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 9-15-2000	Release	Rev 1.0
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx.  (Peripheral Independent).
;================================================================================
; Routine Name: Q Multiplication                     Routine Type: C Callable
;
;
;  C prototype : int mul_q(int NO_1, int Q_1, int NO_2, int Q_2, int Q_result);  
;
; where the NO_1 is the number in Q_1 system
;       the NO_2 is the number in Q_2 system 	
;	  the Q_result is the Q system for the result of NO_1*NO_2
;
; Note that Q_1 (or Q_2) could be higher than 15 (e.g., 16,...,31) for a 
; very low number of NO_1 (or NO_2). If that is the case, NO_1 (or NO_2) must be
; only the positive number.
; 
;================================================================================
;
;        Frame Usage Details:
;     step   |      a      |      b       |      c      |     d     
;____________|_____________|______________|_____________|_____________
;     FR0  	 | right_shift |    result    |             |     
;
;================================================================================
                .def        _mul_q
;================================================================================
__mul_q_framesize 	.set 0001h
;================================================================================
_mul_q:            
     	POPD	*+									; Keep return address
       	SAR  	AR0,*+								; Keep old frame pointer (FP)
       	SAR   	AR1,*								; Keep old stack pointer (SP)
       	LARK  	AR0,__mul_q_framesize 	 			; Load AR0 with frame size	
       	LAR   	AR0,*0+,AR0							; AR0->FP0 (new FP), ARP=AR0
;================================================================================
       	SBRK	#3		; ARP=AR0, AR0->FR0-3 (1st argument)	
;----------------------------------------------------------------------------------
		SETC	SXM		; Turn sign extension mode on
						; ARP=AR0, AR0->NO_1
;----------------------------------------------------------------------------------
		SETC	OVM		; Set overflow mode
						; ARP=AR0, AR0->NO_1
;----------------------------------------------------------------------------------
 		SPM     0       ; Reset product mode
       					; ARP=AR0, AR0->NO_1 
;----------------------------------------------------------------------------------
		LT     	*-		; TREG = NO_1  (Q_1)
						; ARP=AR0, AR0->Q_1			
;----------------------------------------------------------------------------------
		LACC	*-		; ACC = Q_1
						; ARP=AR0, AR0->NO_2
;----------------------------------------------------------------------------------
       	MPY    	*-     	; PREG = NO_1*NO_2 (Q_1+Q_2)
       					; ARP=AR0, AR0->Q_2
;----------------------------------------------------------------------------------
		ADD		*-		; ACC = Q_1+Q_2
       					; ARP=AR0, AR0->Q_result
;----------------------------------------------------------------------------------
     	SUB		*		; ACC = Q_1+Q_2-Q_result
     					; ARP=AR0, AR0->Q_result
;----------------------------------------------------------------------------------
		SUB		#1		; ACC = Q_1+Q_2-Q_result-1 (minus 1 for RPT purpose)
                        ; ARP=AR0, AR0->Q_result
;----------------------------------------------------------------------------------
     	ADRK	#7		; ARP=AR0, AR0->FR0
;----------------------------------------------------------------------------------
      	SACL	*		; FR0 = right_shift = Q_1+Q_2-Q_result-1
      					; ARP=AR0, AR0->FR0		
;----------------------------------------------------------------------------------
      	PAC				; ACC = NO_1*NO_2 (Q_1+Q_2)
                        ; ARP=AR0, AR0->FR0
;----------------------------------------------------------------------------------
		RPT		*		; Repeat right shift with Q_1+Q_2-Q_result times
                        ; ARP=AR0, AR0->FR0
;----------------------------------------------------------------------------------
      	SFR				; ACC = NO_1*NO_2 (Q_result)
                        ; ARP=AR0, AR0->FR0
;----------------------------------------------------------------------------------
		SACL	*		; FR0 = result = NO_1*NO_2 (Q_result)	
                        ; ARP=AR0, AR0->FR0
;----------------------------------------------------------------------------------
		LACL	*,AR1	; ACC = result = NO_1*NO_2 (Q_result)
						; ARP=AR0, AR0->FR0, ARP=AR1 		
;----------------------------------------------------------------------------------
_mul_q_exit:
       	;MAR     *,AR1   ; can be removed if this condition is met on
       	;                ; every path to this code. (i.e., ARP=AR1 here)

        CLRC	OVM
        CLRC	SXM

        SBRK 	#(__mul_q_framesize+1)
        LAR  	AR0,*-
        PSHD	*
        
        RET
      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -