What encoding field distinguishes SRA from SRL?
They share opcode=0110011 and funct3=101; SRA uses funct7=0100000, while SRL uses funct7=0000000.
Shift rs1 right arithmetically by the low log2(XLEN) bits of rs2, result in rd
SRA is an R-type arithmetic right shift. It shifts rs1 right by the amount in the low log2(XLEN) bits of rs2: rs2[4:0] on RV32 and rs2[5:0] on RV64. High bits are filled with the original most-significant bit of rs1, low bits shifted out are discarded, and rd receives the result. opcode=0110011, funct3=101, funct7=0100000; with the same funct3, funct7=0000000 selects SRL.
Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.
This example uses fixed initial register values and PC=0x2000; instruction fetch succeeds, with no asynchronous interrupt or extra extension checks. Exception branches stop ordinary commit; post-trap PC and handler state are EEI-dependent.
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.
SRA shifts rs1 right arithmetically, filling high bits with its original sign bit. Negative results round down, unlike DIV rounding toward zero.
Understand this scenario with real code like «sra x5, x6, x7 # x5 = x6 >> (x7[4:0] on RV32, x7[5:0] on RV64) (arithmetic)».
Understand this scenario with real code like «sra x5, x6, x7 # x5 = x6 >> (x7[4:0] on RV32, x7[5:0] on RV64) (arithmetic)».
They share opcode=0110011 and funct3=101; SRA uses funct7=0100000, while SRL uses funct7=0000000.
Not unconditionally. Sign-filling arithmetic right shift gives -2 for -3 shifted by 1; RISC-V DIV rounds -3 / 2 toward zero to -1.