📄 bit_reverse.c
字号:
/******************************************************************************
; Module: Bit_reverse
; Filename: Bit_reverse.c
; Project: DSP library for XC166 microcontroller
;------------------------------------------------------------------------------
; Compiler: Keil
;
; Version: V1.2
;
; Description: Reversing the binary bit of the input indices during the
; FFT operation. This routine is especially written for FFT.
;
; Date: May 2003
;
; Copyright: Infineon Technologies AG
;*****************************************************************************/
/******************************************************************************
; DataS Bit_reverse(DataS* X, DataS N);
;
; INPUTS:
; X the input index vector
; N the size of the vector
;
; RETURN:
;
; ALGORITHM: befor bit reverse: b7.b6.b5.b4.b3.b2.b1.b0
; after bit reverse: b0.b1.b2.b3.b4.b5.b6.b7
;
; REGISTER USAGE:
; 1. From .c file to .asm file:
; defined by compiler
;
; 2. From .asm file to .c file:
; (R4) = exponent of N
;
; Assumption: 1. N must be in the form 2^M, where M in an integer.
; 2. 2 <= N <= 2048
;
;*****************************************************************************/
#include "DspLib_Keil.h"
DataS Bit_reverse(DataS* X, DataS N)
{
__asm
{
MOV R1,N ;(R1)=N
//determinate the exponent of N
MOV R2,#0ffffh ; clesr register R2=-1
next:
ADD R2,#01h ;(R2)=(R2)+1
SHR R1,#1h ;(R1)=N/2
JMPR cc_NZ, next ;if (R1)>0, jump
//output the exponent of N to R4
MOV R4,R2 ;(R4)=(R2)=exponent of N
//bit reverse
//if N=2, one bit
CMP R2,#1
JMPR cc_NE,Neq2 ;if (R2) not equal to 1, jump
RET
//if N=4, 2 bits
Neq2:
CMP R2,#2
JMPR cc_NE,Neq3 ;if (R2) not equal to 2, jump
loop2:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.1,R3.0 ;bit reverse
BMOV R2.0,R3.1
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;just increase the address of X
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop2 ;if (N)>0, jump
RET
//if N=8, 3 bits
Neq3:
CMP R2,#3
JMPR cc_NE,Neq4 ;if (R2) not equal to 3, jump
loop3:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.2,R3.0 ;bit reverse
BMOV R2.0,R3.2 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop3 ;if (N)>0, jump
RET
//if N=16, 4 bits
Neq4:
CMP R2,#4
JMPR cc_NE,Neq5 ;if (R2) not equal to 4, jump
loop4:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.3,R3.0 ;bit reverse
BMOV R2.2,R3.1 ;bit reverse
BMOV R2.1,R3.2 ;bit reverse
BMOV R2.0,R3.3 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(X)=(X)-1
JMPR cc_NZ,loop4 ;if (N)>0, jump
RET
//if N=32, 5 bits
Neq5:
CMP R2,#5
JMPR cc_NE,Neq6 ;if (R2) not equal to 5, jump
loop5:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.4,R3.0 ;bit reverse
BMOV R2.3,R3.1 ;bit reverse
BMOV R2.1,R3.3 ;bit reverse
BMOV R2.0,R3.4 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop5 ;if (N)>0, jump
RET
//if N=64, 6 bits
Neq6:
CMP R2,#6
JMPR cc_NE,Neq7 ;if (R2) not equal to 6, jump
loop6:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.5,R3.0 ;bit reverse
BMOV R2.4,R3.1 ;bit reverse
BMOV R2.3,R3.2 ;bit reverse
BMOV R2.2,R3.3 ;bit reverse
BMOV R2.1,R3.4 ;bit reverse
BMOV R2.0,R3.5 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop6 ;if (N)>0, jump
RET
//if N=128, 7 bits
Neq7:
CMP R2,#7
JMPR cc_NE,Neq8 ;if (R2) not equal to 7, jump
loop7:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.6,R3.0 ;bit reverse
BMOV R2.5,R3.1 ;bit reverse
BMOV R2.4,R3.2 ;bit reverse
BMOV R2.2,R3.4 ;bit reverse
BMOV R2.1,R3.5 ;bit reverse
BMOV R2.0,R3.6 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop7 ;if (N)>0, jump
RET
//if N=256, 8 bits
Neq8:
CMP R2,#8
JMPR cc_NE,Neq9 ;if (R2) not equal to 8, jump
loop8:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.7,R3.0 ;bit reverse
BMOV R2.6,R3.1 ;bit reverse
BMOV R2.5,R3.2 ;bit reverse
BMOV R2.4,R3.3 ;bit reverse
BMOV R2.3,R3.4 ;bit reverse
BMOV R2.2,R3.5 ;bit reverse
BMOV R2.1,R3.6 ;bit reverse
BMOV R2.0,R3.7 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop8 ;if (N)>0, jump
RET
//if N=512, 9 bits
Neq9:
CMP R2,#9
JMPR cc_NE,Neq10 ;if (R2) not equal to 9, jump
loop9:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.8,R3.0 ;bit reverse
BMOV R2.7,R3.1 ;bit reverse
BMOV R2.6,R3.2 ;bit reverse
BMOV R2.5,R3.3 ;bit reverse
BMOV R2.3,R3.5 ;bit reverse
BMOV R2.2,R3.6 ;bit reverse
BMOV R2.1,R3.7 ;bit reverse
BMOV R2.0,R3.8 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop9 ;if (N)>0, jump
RET
//if N=1024, 10 bits
Neq10:
CMP R2,#10
JMPR cc_NE,Neq11 ;if (R2) not equal to 10, jump
loop10:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.9,R3.0 ;bit reverse
BMOV R2.8,R3.1 ;bit reverse
BMOV R2.7,R3.2 ;bit reverse
BMOV R2.6,R3.3 ;bit reverse
BMOV R2.5,R3.4 ;bit reverse
BMOV R2.4,R3.5 ;bit reverse
BMOV R2.3,R3.6 ;bit reverse
BMOV R2.2,R3.7 ;bit reverse
BMOV R2.1,R3.8 ;bit reverse
BMOV R2.0,R3.9 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop10 ;if (N)>0, jump
RET
//if N=2048, 11 bits
Neq11:
CMP R2,#11
JMPR cc_NE,Neq12 ;if (R2) not equal to 11, jump
loop11:
MOV R3,[X] ;(R3)=x[i]
MOV R2,R3 ;(R2)=(R3)
BMOV R2.10,R3.0 ;bit reverse
BMOV R2.9,R3.1 ;bit reverse
BMOV R2.8,R3.2 ;bit reverse
BMOV R2.7,R3.3 ;bit reverse
BMOV R2.6,R3.4 ;bit reverse
BMOV R2.4,R3.6 ;bit reverse
BMOV R2.3,R3.7 ;bit reverse
BMOV R2.2,R3.8 ;bit reverse
BMOV R2.1,R3.9 ;bit reverse
BMOV R2.0,R3.10 ;bit reverse
MOV [X],R2 ;x[i]=(R2)
MOV R2,[X+] ;increase the address
SUB N,#1 ;(N)=(N)-1
JMPR cc_NZ,loop11;if (N)>0, jump
RET
Neq12:
RET
}
}
//------------------- END OF FILE ----------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -