Arithmetic, logic and shifts
The previous topic ran programs and treated instructions as mnemonics. The processor sees 32-bit words — 0x006283b3 for add t2, t0, t1, or the auipc/addi pair from la.
Notation. rd, rs1, rs2, imm; is register ; sign-extends; arithmetic is mod . is bits down to .
Baseline. Laying each instruction out as written fails twice: a 32-bit constant never fits beside an opcode, and if rs1 moves between formats the decoder cannot start the register-file read until it knows the instruction — that delay hits every op. RISC-V answers with fixed register field positions and a separate recipe for wide constants.
RV32I compute ops (register–register and register–immediate): add/addi, sub, and/andi, or/ori, xor/xori, shifts sll/slli, srl/srli, sra/srai, compares slt/slti, sltu/sltiu. Immediate is a sign-extended 12-bit constant (−2048…2047). No subi: use negative addi. Shift amount = low 5 bits (sll with amount 33 shifts by 1). No flags; no overflow traps. M adds mul (low 32 of the 64-bit product), mulh/mulhu/mulhsu, div/divu (toward zero), rem/remu. Pseudos: mv, neg, not=xori rd,rs,-1, seqz=sltiu rd,rs,1, snez=sltu rd,zero,rs.
Worked. t0=-20 (0xffffffec). srai by 2 → −5; srli → 0x3ffffffb (large positive); slli by 2 → −80. slti vs 1 yields 1; sltiu yields 0 because unsigned is huge. : mul returns 0 while mulhu returns 1.