Bit Reversal for FFT Addressing

Medium Assembly DSP Asked at Analog Devices
Solve this problem

Reverse the low N bits of an index in assembly, which is the address permutation a radix-2 FFT needs before its butterflies start.

Constraints

  • Index in r0, bit width in r1, result in r0.
  • Only the low r1 bits participate.
  • Must handle widths from 1 to 16.
  • Use the RBIT instruction plus a shift, not a loop.
  • Preserve r2 and above.
  • Result must have zeros above bit r1-1.
Starter codeAssembly
1.global bit_reverse2bit_reverse:3    @ r0 = index, r1 = width4    @ TODO5    bx lr