📄 example 2-18.asm
字号:
;Example 2 - 18. Fixed-Point Logarithm ASM Listing for C54x
;================================================================
; This routine is used to calculate the logarithm of an integer
; which is between 0 and 32768. It is programmer’s responsibility
; to validate the input value and make sure DP points to the data page
; of N and X.
; Input: AL = integer, AH = 0
; Output: AL = fraction part in Q11 format and MSB 5bits are integer
; part
; AH = 0
; Register used: B, T, AR0, AR3
; Memory: 30 words
;================================================================
.mmregs
.def log
.data
logtbl .int 21293, 19874, 18454, 17035, 15615, 14196, 12776
.int 11357, 9937, 8517, 7098, 5678, 4259, 2839, 1420, 0
; logtbl is in Q11 format. Logtbl is generated
; by equation 2048*n*ln2.
; This table is starting from n=15 down to n=0.
a9 .int –3277, –3641, –4096, –4681, –5461, –6554, –8192
.int –10923, –16384, –32768, 0, 0
; a9 is in Q15 format. It is generated by equation
; –32768/n. In order to take the advantage of
; instruction POLY, it is organized in reverse
; order, which means n start from 10 down to 1.
; Extra 2 word memory space is reserved to reduce
; the possibilities of data over–written.
.bss N, 1 ; N stores scaling number
.bss X, 1 ; X is temporary storage.
; Must be at the same data page of N.
.text
log:
ADD #0, A, B ; B=A=is
EXP B ; T=leading 0s
LD #0x4000, 16, A ; AH=16384, the largest supported scale
ST T, N ; store scaling number
ANDM #0Fh, N ; compensate extra 16 leading;bits
MVDM N, AR0 ; AR0 index to segment table
NORM B ; normalize to Q15 format
AND #0x3FFF, 16, B ; BH=BH–0x4000
BC taylor, BNEQ ; if (B==0) which means it takes 2^N form
; then index to the pre–stored table
STM #logtbl+1, AR3 ; and return the value
MAR *AR3+0
LD *AR3, A
RET
taylor:
SUB B, 0, A ; A=A–B, A is the x in Taylor’s equation
STH A, X ; X is the fractional part in Q15 format
STM a9, AR3 ; AR3 points to coefficient in Taylor’s equ.
LD X, T ; set up running environment using
LD *AR3+, 16, A ; powerful poly instruction on c54x DSP
LD *AR3+, 16, B ;
RPT #10 ; loop 11 times enough for audio
; app.
POLY *AR3+ ; AH=fractional part in Q15 format
SFTA A, –16 ; AL=AH
SFTA A, –4 ; AL is now in Q11 format
STM #logtbl, AR3 ; s um up scaling part
MAR *AR3+0
ADD *AR3, A
RET
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -