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

📄 qexp.asm

📁 变频器程序
💻 ASM
字号:
;===========================================================
;
; File Name     :qexp.asm
; 
; Originator    :Hust 
;                
; 
; Description   :This file contain source code for Fixed point exp
;               
; Date          : 3/13/2003
;==========================================================
; 
; 
; Routine Name  : Generic Function      
; Routine Type  : C Callable
; 
; Description   :
; signed int qexp(signed int x)
;
; Algorithm     :
; exp(x):  x is in scaled Q13 format
;       = ((((0.0417*x)+0.1667)*x+0.5)*x+1)*x+1  when -&<x<&
;       
;========================================================================
; Pseudo Code
;======================================================================
;
; signed int qsin(signed int x)
; { 
;   int y;
;   temp=abs(x);
;   y=appx(temp);   /* Sin approximation for positive value of 'x' */
;   
;   if(x<0)
;   {
;       y=-y;
;   }
;   return y;
; } 
;
;====================================================================
; Function Local Frame
;====================================================================
;   |_______|
;   |_______|<- Stack Pointer                           (FP+2) <---AR1
;   |_______|<- Register to Register Tfr & Computation  (FP)   <---AR0 
;   |_______|<- Old FP                                  (FP-1)
;   |_______|<- Return Address of the Caller            (FP-2) 
;   |_______|<- Formal parameter X                      (FP-3) <---AR2
;======================================================================   
; Module definition for external referance
            .def    _qexp
__exp_frs   .set    00001h          ; Local frame size for this routine
__a0        .set    04000h          ; 1 scaled by 2^14
__a1        .set    04000h          ; 1 scaled by 2^14
__a2        .set    04000h          ; 0.5 scaled by 2^15
__a3        .set    0555ah          ; 0.1667 scaled by 2^17
__a4        .set    002abh          ; 0.0417 scaled by 2^14for short immediate MPY

_qexp:      
            POPD    *+              ; Store the Return Address in stack
            SAR     AR0,*+          ; Store the Caller's Frame Pointer
            SAR     AR1,*
            LAR     AR0,#__exp_frs      
            LAR     AR0,*0+,AR2     ; Create Local frame for sin function
                                     
            SETC    SXM             
            SETC    OVM
            LAR     AR2,#0FFFDh      
            MAR     *0+             ; Modify AR2 to point to x
            LACC    *,16,AR0        ; ACC=x, where x is in scaled Q13 Format
            SFR
            SFR
            SACH    *               ;             
            LT      *               ; TREG=x in scaled Q13 format 
 
            MPY     #__a4           ; P=x*a4 in Q27   
            LACC    #__a3,10        ; ACC=a3 in Q27
            APAC                    ; ACC=a3+x*a4 in Q27
			SACH    *,5             ; Store a3+x*a4 in Q16

            
            MPY     *               ; P=x*(a3+x*a4) in Q29
            LACC    #__a2,14        ; ACC=a2 in Q29
            APAC                    ; ACC=a2+x*(a3+x*a4) in Q29
            SACH    *               ; Store a2+x*(a3+x*a4) in Q13
            
                       
            MPY     *               ; P=x*(a2+x*(a3+x*a4)) in Q26
            LACC    #__a1,12        ; ACC=a1 in Q26
            APAC                    ; ACC=a1+x*(a2+x*(a3+x*a4)) in Q26
            SACH    *,3             ; Store a1+x*(a2+x*(a3+x*a4)) in Q13

            MPY     *               ; P=x*(a1+x*(a2+x*(a3+x*a4))) in Q26
            LACC    #__a0,12         ; ACC=a0 in Q26
            APAC                    ; ACC=a0+x*(a1+x*(a2+x*(a3+x*a4))) in Q26
            SACH    *,3             ; Store ACC in Q13 format
            

            
            LACC    *,0,AR2         ; Return the result
            BIT     *,0,AR1
;            BCND    positive,NTC
;            CMPL                    ; Negate the result, if input is negative

positive:
            CLRC    OVM
            SBRK    #(__exp_frs+1)  ; Clear the local frame
            LAR     AR0,*-          ; Retrive Caller's frame pointer
            PSHD    *               ; Push the return address to TOS
            RET                     ; Return to the caller
    
            

⌨️ 快捷键说明

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