Assembly Language Programming

Shift and Rotate Introduction

In Lecture 2, the logical operations (AND, ORR, EOR, BIC) were introduced. These are not the only bitwise operations, however. Another important category is the shift and rotate operations.

At their most basic, a shift operation moves the bits in a register to the left or right and filling the vacant holes with zeros or ones. For instance, shifting bits left by one bit is equivalent to multiplying the original number by 2. Shifting bits right is equivalent to division. Thus shift operations can simulate certain forms of integer multiplication and division.

Why not just use generic multiply and divide instructions? Firstly the ARM, like many processors, does not have an integer division instruction. Secondly generic multiplication and division is a slow process - in many cases, it will much faster to convert standard multiplication and division calculations into a series of shift operations.

In most processor architectures, shift and rotate instructions are distinct instructions. In the ARM architecture, shift and rotate are special operands that can be applied to one of the register operands of any data processing instruction. A shift or a rotate can be performed at the same time as an ADD or a MOV instruction because the ARM incorporates extra hardware, namely a "barrel shifter", into its Arithmetic and Logic Unit.

Shift and rotate operands can be applied to any of the following ARM instructions: ADC, ADD, AND, BIC, CMN, CMP, EOR, MOV, MVN, ORR, RSB, SBC, SUB, TEQ, TST.

Shift and rotate operands can also be applied to registers used for calculating addresses in LDR and STR instructions.