Barrel Shifter


The barrel shifter is capable of shifting a 40-bit value, up to 16bits right or left, in a single cycle. The source can be either of the two DSP accumulators or the X bus, to support multi-bit shifts of register or memory data. The shifter requires a signed binary value to determine both the magnitude (number of bits) and direction of the shift operation. A positive value shifts the operand right. A negative value shifts the operand left. A value of ‘0’ does not modify the operand.

The barrel shifter can be used by both MCU and DSP instructions. The barrel shifter is 40 bits wide, thereby obtaining a 40-bit result for DSP shift operations and a 16-bit result for MCU shift operations. Data from the X bus is presented to the barrel shifter between bit positions 16 to 31 for right shifts, and between bit positions 0 to 16 for left shifts.

  • Single cycle ±16-bit shift
    • Shift left
    • Logical shift right - ignores sign bit
    • Arithmetic shift left - retains sign bit
  • ASR, LSR & SL are identical in dsPIC® DSC and PIC24
  • Rotate instructions (RRC, etc.) do not use barrel shifter

Barrel shifter instructions

Instruction Description
ASR Arithmetic multi-bit right shift of data memory
LSR Logical multi-bit right shift of data memory
SL Multi-bit shift left of data memory
SAC Store DSP accumulator with optional shift
SAC.R Store Rounded DSP accumulator with optional shift
SFTAC Shift DSP Accumulator

ASR, LSR, and SL operate on the ALU, while SAC, SAC.R, and SFTAC operate on the accumulators.


The first example is using the arithmetic multi-bit right shift of data memory,asr instruction, while the second example utilizes the logical multi-bit right shift of data memory, lsr instruction. The third example performs a multi-bit left shift, and the last example shows the DSP Accumulator shift.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.