ISA & Assembly

When C's "a * b" (multiplying two ints) is compiled for an RV32I CPU without the M extension, what generally happens?

  1. AIt becomes a call to a library function that multiplies by repeated shifts and adds
  2. BMultiplication is unavailable, so compilation fails
  3. CThe M extension's mul instruction is emitted and added automatically at run time
Show answer and explanation

Answer: A. It becomes a call to a library function that multiplies by repeated shifts and adds

For CPUs without a multiplier, the compiler replaces multiplication with a call to a helper library function such as __mulsi3. That function computes the product the same way as long multiplication: it examines one operand bit by bit and, for each 1, adds the correspondingly shifted other operand. The answer is correct but much slower than a hardware multiplier. Omitting an ISA extension makes the circuit smaller at the cost of slower processing.

  • A. Correct. Software does the work instead of hardware.
  • B. C multiplication works for any target CPU.
  • C. Executing a nonexistent instruction raises an illegal-instruction exception.