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

📄 example 3-7.asm

📁 《基于TI DSP的通用算法实现》程序代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
; Stage 5 - using BUTTFLYI Macro
;==============================================================================
STAGE5:
	MAR *, AR2 ;-->AR2
	LAR AR0, #4 ;Used to Inc Twiddle pointers
	LAR AR1, #(B0_SADR) ;-->P (0-->15)
	LAR AR2, #(B0_SADR+32) ;-->Q (16-->31)
	LAR AR5, #B2_SADR ;Gen purp reg @ 60h

;---------------------------------------------------------------------------
	STG5_BLK1 LAR AR3, #(TWID_TBL+N/4) ;COS(angle)
	LAR AR4, #(TWID_TBL) ;COS(angle+pi/4)
	LAR AR7, #(N/8-1) ;Loop counter (16 times)
STAGE51_LP:
	BFLY 7
	BANZ	STAGE51_LP,*-,AR2

;---------------------------------------------------------------------------
	STG5_BLK2:
	LAR AR1, #(B0_SADR+64) ;-->P (32-->47)
	LAR AR2, #(B0_SADR+96) ;-->Q (48-->63)
	LAR AR3, #(TWID_TBL+N/4) ;COS(angle)
	LAR AR4, #(TWID_TBL) ;COS(angle+pi/4)
	LAR AR7, #(N/8-1) ;Loop counter (16 times)
STAGE52_LP:
	BFLY 7
	BANZ	STAGE52_LP,*-,AR2

;---------------------------------------------------------------------------
STG5_BLK3:
	LAR AR1, #(B0_SADR+128) ;-->P (64-->79)
	LAR AR2, #(B0_SADR+160) ;-->Q (80-->95)
	LAR AR3, #(TWID_TBL+N/4) ;COS(angle)
	LAR AR4, #(TWID_TBL) ;COS(angle+pi/4)
	LAR AR7, #(N/8-1) ;Loop counter (16 times)

STAGE53_LP:
	BFLY 7
	BANZ	STAGE53_LP,*-,AR2

;---------------------------------------------------------------------------
STG5_BLK4:
	LAR AR1, #(B0_SADR+192) ;-->P (96-->111)
	LAR AR2, #(B0_SADR+224) ;-->Q (112-->127)
	LAR AR3, #(TWID_TBL+N/4) ;COS(angle)
	LAR AR4, #(TWID_TBL) ;COS(angle+pi/4)
	LAR AR7, #(N/8-1) ;Loop counter (16 times)
STAGE54_LP:
	BFLY 7

	BANZ	STAGE54_LP,*-,AR2
;==============================================================================
; Stage 6 - Using BFLY Macro
;==============================================================================
STAGE6:
	MAR *, AR2 ;-->AR2
	LAR AR0, #2 ;used to Inc Twiddle pointers
	LAR AR1, #(B0_SADR) ;-->P (0-->31)
	LAR AR2, #(B0_SADR+64) ;-->Q (32-->63)
	LAR AR5, #B2_SADR ;Gen purp reg @ 60h
;---------------------------------------------------------------------------
	STG6_BLK1 LAR AR3, #(TWID_TBL+N/4) ;COS(angle)
	LAR AR4, #(TWID_TBL) ;COS(angle+pi/4)
	LAR AR7, #(N/4-1) ;Loop counter (32 times)
STAGE61_LP:
	BFLY 7
	BANZ	STAGE61_LP,*-,AR2

;---------------------------------------------------------------------------
STG6_BLK2:
	LAR AR1, #(B0_SADR+128) ;-->P (64-->95)
	LAR AR2, #(B0_SADR+192) ;-->Q (96-->127)
	LAR AR3, #(TWID_TBL+N/4) ;COS(angle)
	LAR AR4, #(TWID_TBL) ;COS(angle+pi/4)
	LAR AR7, #(N/4-1) ;Loop counter (32 times)
STAGE62_LP:
	BFLY 7
	BANZ	STAGE62_LP,*-,AR2

;==============================================================================
; Stage 7 - Using BFLY Macro
;==============================================================================
STAGE7:
	MAR *, AR2 ;-->AR2
	LAR AR0, #1 ;Used to Inc Twiddle pointers
	LAR AR1, #(B0_SADR) ;-->P (0-->63)
	LAR AR2, #(B0_SADR+128) ;-->Q (64-->128)
	LAR AR5, #B2_SADR ;Gen purp reg @ 60h
	LAR AR3, #(TWID_TBL+N/4)
	LAR AR4, #(TWID_TBL)
	LAR AR7, #(N/2-1) ;Loop counter (64 times)
STG_7_LP BFLY 7

	BANZ STG_7_LP,*-,AR2
;==============================================================================
; Convert Real/Img into Magnitude ( Mag = sqr(Xr[n]) + sqr(Xi[n]) )
;==============================================================================
	LAR AR1, #B0_SADR
	LAR AR2, #B1_SADR
	LARKAR3, #127 ;loop 128 times
	LAR AR4, #(B1_SADR+128)
	MAR *, AR1
	MAG_LP ZAC
	MPYK0
	SQRA	*+ ;Xr[n]**2
	SQRA	*+,AR2 ;Xi[n]**2
	APAC
	SACH	*+,0,AR4
	SACH	*+,0,AR3 ;XOUT(I) = X(I)**2 + Y(I)**2
	BANZ	MAG_LP,*-,AR1

;==============================================================================
; Normalize Values of the FFT
;==============================================================================
.bssMAX,1
.bssQUOTIENT,1
.text
	NOP
	LAR AR1,#(B1_SADR+128)
	LAR AR2,#127
	LDP #0
	SPLK	#0,MAX ;Initialize the variable MAX
	SPLK	#0,QUOTIENT ;Initizlize the variable QUOTIENT
		;The following section finds the maximum value among the FFT magnitudes
	MAR *,AR1 ;ARP = AR1
	FIND_MAX LACC*+,0,AR2 ;ACC = Value pointed by AR1; AR1 = AR1+1
	SUB MAX ;Subtract MAX
	BCND	RESUME,LEQ ;If the result is less than zero, then
		;the value is not larger than MAX, else
	ADD 	MAX
	SACL	MAX ;Store the new MAX value
RESUME 	BANZ	FIND_MAX,*-,AR1 ;Go through all the magnitudes to find the
		;maximum value, then normalize the values
		;The following section makes everything a ratio according to the maximum value
	LAR AR1,#(B0_SADR+256) ;AR1 = B1_SADR
	LAR AR2,#127 ;AR2 = 128-1; Number of Magnitudes to Normalize
	LAR AR3,#(B1_SADR+128) ;AR3 = B1_SADR + 128
	LAR AR4,#MAX ;AR4 = Address for MAX value
	LAR AR5,#QUOTIENT ;AR5 = Address for Q15 quotient
	LAR AR6,#15 ;AR6 = 16 - 1; Number of times to subtract
	MAR *,AR5 ;ARP = AR5
DIVIDING 
	LACC* ;ACC = QUOTIENT
	SACL*,1,AR3 ;QUOTIENT = QUOTIENT * 2; 1st shift doesn't matter
		;because QUOTIENT = 0
	LACC	*,0,AR4 ;ACC = Value pointed by AR3
	SUB * ;Subtract MAX
	BCND	ADD_ONE,GEQ ;If ACC is still positive, then increment

		;the ones place of the quotient, and shift
		;the remainder in the ACC, else
		;shift the remainder in the ACC
		;Check the following section to reduce unnecessary instructions
	ADD 	*,AR3
	SAC	L*,1,AR6 ;Store the remainder * 2 to location
		;pointed by AR3
	BANZ	DIVIDING,*-,AR5 ;AR6 = AR6 - 1; Repeat the dividing
	B NEXT_VALUE ;After repeating 16 times, fetch another
		;value
	ADD_ONEMAR *,AR3 ;ARP = AR3
	SACL*,1,AR5 ;Store the Remainder shifted by 1 back
		;into the buffer
	LACC* ;ACC = Quotient
	ADD #1 ;Increment the quotient
	SACL*,0,AR6 ;Store the new value of quotient; ARP = AR6
	BANZ	DIVIDING,*-,AR5 ;AR6 = AR6 - 1; Repeat the dividing
	B NEXT_VALUE
NEXT_VALUE 
	LAR AR6,#15 ;Reset AR6 to 15
	MAR *,AR3 ;ARP = AR3
	SACL*+,0,AR5 ;Store the quotient into the buffer
	SPLK#0,*,AR2 ;Clear the variable QUOTIENT
	BANZ	DIVIDING,*-,AR5 ;Repeat the dividing routine for all 128 values
			;The following section corrects the value obtained when the maximum value is
			;divided by itself. Changes 8000h to max Q15 value of 7FFFh
	LAR AR1,#(B1_SADR+128)
	LAR AR2,#127
	MAR *,AR1 ;ARP = AR1
CHANGING 
	LACC* ;ACC = Value pointed by AR1
	SUB #8000h ;Subtract 8000h
	BCND	CONTINUE,NEQ ;If equal to 8000h, then
	LACC	#0FFFFh ;ACC = FFFFh, else
CONTINUE 
	ADD #8000h
	SACL*+,0,AR2 ;Check the next value
	BANZ	CHANGING,*-,AR1 ;Go through the entire buffer
			;The following section multiplies the Q15 numbers by the maximum value (FFFh)
			;of the DAC on the EVM
	LAR AR1,#(B1_SADR+128)
	LAR AR2,#127
	MAR *,AR1 ;ARP = AR1
NORMALIZE 
	LT * ;TREG = Value pointed by AR1
	MPY #0FFFh ;Multiply by FFFh
	PAC ;ACC = PREG
	SACH*+,1,AR2 ;Store the high word, elimnate extra sign bit
	BANZ	NORMALIZE,*-,AR1 ;Normalize all of the magnitudes

;==============================================================================
; Output the values on the DAC of the EVM
;==============================================================================
	LAR AR1, #B1_SADR ;AR1 = Beginning of Un-normalized magnitudes
	LAR AR2, #63 ;AR2 = 64 - 1; Display first 64 magnitudes
	MAR *,AR1 ;ARP = AR1
	LDP #0
	SPLK	#2,uSEC ;Variable uSEC = 2
			;The following section outputs the un-normalized values
		;OUTPUTSETCXF ;Set XF high
		; LACC*+,AR2 ;ACC = value pointed by AR1
		; SACLDAC0VAL ;DAC0VAL = ACC
		; OUT DAC0VAL,DAC0 ;Write value to channel 0 of DAC
		; OUT DAC0VAL,DACUPDATE ;Output the value
		; CALLDELAY ;Wait
		; MAR *,AR2 ;ARP = AR2
		; BANZOUTPUT,*-,AR1 ;Output the remaining values
		; CLRCXF ;Clear XF once all values have been output
	LAR AR1, #(B1_SADR+128) ;AR1 = Beginning of normalized magnitudes
	LAR AR2, #63 ;AR2 = 64 -1; Display first 64 magnitudes
	MAR *,AR1 ;ARP = AR1
		;The following section outputs the normalized values
OUTPUT2
	SET	CXF ;Set XF high
	LACC*+,AR2 ;ACC = value pointed by AR1
	SACL	DAC0VAL ;DAC0VAL = ACC
	OUT DAC0VAL,DAC0 ;Write value to channel 0 of DAC
	OUT DAC0VAL,DACUPDATE ;Output the value
	CALL	DELAY ;Wait
	MAR *,AR2 ;ARP = AR2
	BANZ	OUTPUT2,*-,AR1 ;Output the remaining values
	SPLK #0,DAC0VAL ;DAC0VAL = 0
	OUT DAC0VAL,DAC0 ;Clear channel 0 of DAC
	OUT DAC0VAL,DACUPDATE ;Output 0V
	CLRCXF ;Clear XF
	REPEAT ;Go back and wait for next 128 samples
	DEND B DEND

;=====================================================================
; Routine Name: DELAY
;
; Description:Produces a multiple of 1.6uS delays using the RPT
; instruction. The Delay produced is based on the
; value loaded in uSEC (i.e. Delay = uSEC x 1.6mS).
; Indirect addressing is used to count the number
; of times the delay loop is repeated.
;
; Calling Convention:
;
; Variables on Entry on Exit
; --------------------------------------------------------------------
; DP XX 0x0000
; ARP XX AR7
; ACC XX XX
; uSEC value in 1.6 uS un-touched
; --------------------------------------------------------------------
;=====================================================================
DELAY:
	LDP #0h ;DP-->0000h-007Fh
	LACC#32
	SACL	RPT_NUM ;RPT_NUM = 32
	LAR AR7,uSEC ;Set AR0 to generate a
	MAR *,AR7 ;(AR0*0.1)mSEC delay loop
DELAY_LOOP: 
	LDP #0h ;DP-->0000h-007Fh
	RPT RPT_NUM ;32 cycles = 1.6uS
	NOP ;1 cycle
	BANZ	DELAY_LOOP ;Repeat DELAY_LOOP
	RET ;Return from DELAY SR

;==============================================================================
; I S R - PHANTOM
;
; Description:Dummy ISR, used to trap spurious interrupts.
;
; Modifies:
;
; Last Update:16-06-95
;==============================================================================

PHANTOM B PHANTOM


;==============================================================================
; TWIDDLES FOR N=128 FFT (96 entries)
;==============================================================================
PS_TWID_STRT:
.word 00000h ; 0.000 
.word 00648h ; 2.812 
.word 00c8ch ; 5.625 
.word 012c8h ; 8.438 
.word 018f9h ; 11.250 
.word 01f1ah ; 14.062 
.word 02528h ; 16.875 
.word 02b1fh ; 19.688 
.word 030fch ; 22.500 
.word 036bah ; 25.312 
.word 03c57h ; 28.125 
.word 041ceh ; 30.938 
.word 0471dh ; 33.750 
.word 04c40h ; 36.562 
.word 05134h ; 39.375 
.word 055f6h ; 42.188 
.word 05a82h ; 45.000 
.word 05ed7h ; 47.812 
.word 062f2h ; 50.625 
.word 066d0h ; 53.438 
.word 06a6eh ; 56.250 
.word 06dcah ; 59.062 
.word 070e3h ; 61.875 
.word 073b6h ; 64.688 
.word 07642h ; 67.500 
.word 07885h ; 70.312 
.word 07a7dh ; 73.125 
.word 07c2ah ; 75.938 
.word 07d8ah ; 78.750 
.word 07e9dh ; 81.562 
.word 07f62h ; 84.375 
.word 07fd9h ; 87.188 
.word 07fffh ; 90.000 
.word 07fd9h ; 92.812 
.word 07f62h ; 95.625 
.word 07e9dh ; 98.438 
.word 07d8ah ; 101.250 
.word 07c2ah ; 104.062 
.word 07a7dh ; 106.875 
.word 07885h ; 109.688 
.word 07642h ; 112.500 
.word 073b6h ; 115.312 
.word 070e3h ; 118.125 
.word 06dcah ; 120.938 
.word 06a6eh ; 123.750 
.word 066d0h ; 126.562 
.word 062f2h ; 129.375
.word 05ed7h ; 132.188 
.word 05a82h ; 135.000 
.word 055f6h ; 137.812 
.word 05134h ; 140.625 
.word 04c40h ; 143.438 
.word 0471dh ; 146.250 
.word 041ceh ; 149.062 
.word 03c57h ; 151.875 
.word 036bah ; 154.688 
.word 030fch ; 157.500 
.word 02b1fh ; 160.312 
.word 02528h ; 163.125 
.word 01f1ah ; 165.938 
.word 018f9h ; 168.750 
.word 012c8h ; 171.562 
.word 00c8ch ; 174.375 
.word 00648h ; 177.188 
.word 00000h ; 180.000 
.word 0f9b8h ; 182.812 
.word 0f374h ; 185.625 
.word 0ed38h ; 188.438 
.word 0e707h ; 191.250 
.word 0e0e6h ; 194.062 
.word 0dad8h ; 196.875 
.word 0d4e1h ; 199.688 
.word 0cf04h ; 202.500 
.word 0c946h ; 205.312 
.word 0c3a9h ; 208.125 
.word 0be32h ; 210.938 
.word 0b8e3h ; 213.750 
.word 0b3c0h ; 216.562 
.word 0aecch ; 219.375 
.word 0aa0ah ; 222.188 
.word 0a57eh ; 225.000 
.word 0a129h ; 227.812 
.word 09d0eh ; 230.625 
.word 09930h ; 233.438 
.word 09592h ; 236.250 
.word 09236h ; 239.062 
.word 08f1dh ; 241.875 
.word 08c4ah ; 244.688 
.word 089beh ; 247.500 
.word 0877bh ; 250.312 
.word 08583h ; 253.125 
.word 083d6h ; 255.938 
.word 08276h ; 258.750 
.word 08163h ; 261.562 
.word 0809eh ; 264.375

PS_TWID_END:
.word 08027h ; 267.188 

⌨️ 快捷键说明

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