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 2
N.
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.)
| User Entry |
| Intermediate Value |
S | 'S' appended for 16-bit instruction |
| Final 32-Bit Product |
| Product Overflow |
|