?? qinv1.asm
字號:
;===========================================================
;
; File Name :qinv1.asm
;
; Originator :Digital Control Systems Group
; Texas Instruments
;
; Description :This file contain source code to find the reciprocal of
; fixed point number, The output is a 32 bit number
; Date : 7/11/2000
;==========================================================
;
;
; Routine Name : Generic Function
; Routine Type : C Callable
;
; Description :
; long int qinv1(int x)
;
; Input format: Signed number in Q(x) format (x<16)
; Output format: Signed number in Q(31-x) format (32 bit result)
;
; Example 1:
; Input format: Signed Q15 format (Fractional Number)
; Output format: Signed Q16 format
;
; Example 2:
; Input format: Signed Q0 format (Integer Number)
; Output format: Signed Q31
;
; Example 3:
; Input format: Signed Q13 format
; Output format: Signed Q18 format
;=================================================================
; Function Local Frame
;=================================================================
; |_______|
; |_______|<- Stack Pointer
; |_______|<- Computation (FP+1)
; |_______|<- Frame ptr (FP)
; |_______|<- Old FP
; |_______|<- Return Address of the Caller
; |_______|<- Formal parameter x in signed m.n format
;==================================================================
; Module definition for external referance
.def _qinv1
__inv1_frs .set 00002h ; Local frame size for this routine
_qinv1:
POPD *+ ; Store the Return Address in stack
SAR AR0,*+ ; Store the Caller's Frame Pointer
SAR AR1,*
LAR AR0,#__inv1_frs
LAR AR0,*0+,AR2 ; Create Local frame for cos function
SETC OVM ; To saturate ABS value of 0x8000 to 0x7fff
SETC SXM
LAR AR2,#0FFFDh
MAR *0+ ; Modify AR2 to point to x, which is in 16.0
LACC *,16,AR3 ; Load the input to the ACCH
LAR AR3,#01h
MAR *0+
BCND calculate,NEQ ; If input is zero, return with ZERO
LACC #0000h
B return
calculate: BCND positive, GT
ABS ; Obtain the absolute value of x<0
positive: SACH * ; Store |x| in 16.0
LACC #01h,15 ; #1 in Q15 format
RPT #15
SUBC * ; Generate first 16 bits of Quotient
MAR *,AR0
SACL *,0,AR3 ; Store the Quotient
AND #0ffffh,16 ; Mask the quotient
RPT #15 ; Generate another 16 quotient bits
SUBC * ; by dividing the remainder from the
; first stage.
AND #0ffffh ; Mask the remainder
MAR *,AR0
ADD *,16,AR2 ; Combine the Quotient bits
ABS ; To convert 8000 0000 to 7fff ffff
isnot1: BIT *,0
BCND return,NTC
NEG
return: CLRC OVM
MAR *,AR1
SBRK #(__inv1_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 + -