Integer Multiplication by a Constant

The ARM Cortex-M4 has a very fast multiply instruction (MUL) that executes in a single clock cycle.

However, the MUL instruction requires that all operands be in registers, so another instruction is needed to load the constant into a register, and thus a minimum of two registers and two clock cycles are required.

Sometimes multiplication by a constant can be accomplished with a single instruction using only one register and one clock cycle. For example, shifting a register left by N bits will multiply its content by 2N. Additional constant multipliers are possible by incorporating the shift within a single ADD, SUB, or RSB instruction.

Although two-instruction replacement sequences are never faster than using a MUL instruction, they can often eliminate the need for a second register.

(Click anywhere to remove this message.)

Integer Multiply by Constant
Revised: Thursday, 23-Jun-2022 20:36:31 PDT
Fastest
Code
Fewest
Regs
Smallest
Code
Preserves
Flags
Include
Redundant
Operands Signed10 Unsigned10 Hex16 ARM Assembly
A (32-bit Multiplicand):
B (32-bit Multiplier Constant):
User
Entry
Intermediate
Value
S'S' appended for
16-bit instruction
Final 32-Bit
Product
Product
Overflow