MUL

RISC-V MUL Instruction Details

Instruction ManualR-type

Multiply rs1 by rs2, store lower XLEN bits of product in rd

Instruction Syntax

mul rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
MArithmeticMultiplication

Instruction Behavior

MUL performs an XLEN-bit × XLEN-bit multiplication of rs1 by rs2 and places the lower XLEN bits of the product in the destination register rd. Product bits above XLEN are not written to rd. It is defined by M and is also included in Zmmul.

MUL Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
mul
,
,
Execution Context
a6(x16)
0xFFFFFFF0
t2(x7)
0x00000007
31..25
24..20
19..15
14..12
11..7
6..0
0000001
funct7
00111
rs2
10000
rs1
000
funct3
00101
rd
0110011
opcode
Execution Data Path
instruction
0x027802B3
opcode
0110011 -> OP
funct3
000 -> MUL
funct7
0000001 -> integer multiply selector
rd / rs1 / rs2
t0(x5) / a6(x16)=0xFFFFFFF0 (4294967280) / t2(x7)=0x00000007 (7)
32-bit multiply
4294967280 x 7 -> full[63:0]=0x00000006FFFFFF90 -> product[31:0]=0xFFFFFF90 (low XLEN bits; operand signedness does not change those bits)
x5
t0(x5) = 0xFFFFFF90
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x027802B3
syntax : mul t0(x5), a6(x16), t2(x7)
result : t0(x5) = 0xFFFFFF90
Architectural Result
t0(x5) = 0xFFFFFF90

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Common Usage Scenarios

XLEN-bit integer multiplication

Understand this scenario with real code like «mul a0, a1, a2 # a0 = (a1 * a2) & ((1 << XLEN) - 1)».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

Overflow is truncated, only low XLEN bits kept
When both halves of one product are needed, use MULH, MULHSU, or MULHU followed by MUL with the same source order; the high-half destination must not equal either source