How is SUB encoded differently from ADD?
They share opcode and funct3. SUB uses funct7=0100000, while ADD uses funct7=0000000.
Subtract rs2 from rs1, place result in rd
SUB (R-type) subtracts rs2 from rs1 (overflow ignored), writing to rd. funct7=0100000, funct3=000. Bit30=1 in funct7 distinguishes SUB from ADD (same funct3/opcode). There is no SUBI; use ADDI with a negated immediate instead.
Uses the same rhythm as the ADDI page: machine-code fields, fixed-field identification, operand reads, instruction-specific execution, and ISA-visible state update.
The machine code is split by the current instruction format; the animation starts from encoding/decode.
This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.
SUB subtracts rs2 from rs1 and writes rd. It is register subtraction; the base integer ISA has no immediate subtract, so subtracting a small constant is normally ADDI with a negative immediate.
Understand this scenario with real code like «sub x5, x6, x7 # x5 = x6 - x7».
Understand this scenario with real code like «sub x5, x6, x7 # x5 = x6 - x7».
Understand this scenario with real code like «sub x5, x6, x7 # x5 = x6 - x7».
They share opcode and funct3. SUB uses funct7=0100000, while ADD uses funct7=0000000.
Use ADDI with a negative immediate, for example addi rd, rs1, -8 to subtract 8.