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 tens of times 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.
Practice this topic Back to topic

More ISA & Assembly questions

  1. What is true of the branch delay slot found in older ISAs such as MIPS (the rule that the one instruction right after a branch always executes, taken or not)?
  2. On 64-bit RV64I, how does lw place the 32-bit value it loads into a 64-bit register?
  3. Which correctly describes an ABI (application binary interface)?
  4. How is a call through a C function pointer, "(*fp)(x)", generally performed in RISC-V?
  5. Which statement is correct about two CPUs that implement the same instruction set architecture (ISA)?