Instructions

Base Integer Instructions

These base integer instructions are the foundation of the RISC-V architecture.

Loads

InstructionNameRV32IRV64IRV128ISyntax
LBLoad ByteYYYLB rd,rs1,imm
LHLoad HalfwordYYYLH rd,rs1,imm
LWLoad WordYYYLW rd,rs1,imm
LDLoad DoubleNYYLD rd,rs,imm
LQLoad QuadNNYLQ rd,rs,imm
LBULoad Byte UnsignedYYYLBU rd,rs1,imm
LHULoad Halfword UnsignedYYYLHU rd,rs1,imm
LWULoad Word UnsignedNYYLWU rd,rs1,imm
LDULoad Double UnsignedNNYLDU rd,rs1,imm

Stores

InstructionNameRV32IR64IR128ISyntax
SBStore ByteYYYSB rs1,rs2,imm
SHStore HalfwordYYYSH rs1,rs2,imm
SWStore WordYYYSW rs1,rs2,imm
SDStore DoubleNYYSD rs1,rs2,imm
SQStore QuadNNYSQ rs1,rs2,imm

Shifts

InstructionNameRV32IRV64IRV128ISyntax
SLLShift LeftYYYSLL rd,rs1,rs2
SLLWShift Left WordNYYSLLW rd,rs1,rs2
SLLDShift Left DoubleNNYSLLD rd,rs1,rs2
SLLIShift Left ImmediateYYYSLLI rd,rs1,shamt
SLLIWShift Left Immediate WordNYYSLLIW rd,rs1,shamt
SLLIDShift Left Immediate DoubleNNYSLLID rd,rs1,shamt
SRLShift RightYYYSRL rd,rs1,rs2
SRLWShift Right WordNYYSRLW rd,rs1,rs2
SRLDShift Right DoubleNNYSRLD rd,rs1,rs2
SRLIShift Right ImmediateYYYSRLI rd,rs1,shamt
SRLIWShift Right Immediate WordNYYSRLIW rd,rs1,shamt
SRLIDShift Right Immediate DoubleNNYSRLID rd,rs1,shamt
SRAShift Right ArithmeticYYYSRA rd,rs1,rs2
SRAWShift Right Arithmetic WordNYYSRAW rd,rs1,rs2
SRADShift Right Arithmetic DoubleNNYSRAD rd,rs1,rs2
SRAIShift Right Arithmetic Imm.YYYSRAI rd,rs1,shamt
SRAIWShift Right Arithmetic Imm. WordNYYSRAIW rd,rs1,shamt
SRAIDShift Right Arithmetic Imm. DoubleNNYSRAID rd,rs1,shamt

Arithmetic

InstructionNameRV32IRV64IRV128ISyntax
ADDADDYYYADD rd,rs1,rs2
ADDWADD WordNYYADDW rd,rs1,rs2
ADDDADD DoubleNNYADDD rd,rs1,rs2
ADDIADD ImmediateYYYADDI rd,rs1,imm
ADDIWADD Immediate WordNYYADDIW rd,rs1,imm
ADDIDADD Immediate DoubleNNYADDID rd,rs1,imm
SUBSubtractYYYSUB rd,rs1,rs2
SUBWSubtract WordNYYSUBW rd,rs1,rs2
SUBDSubtract DoubleNNYSUBD rd,rs1,rs2
LUILoad Upper ImmediateYYYLUI rd,imm
AUIPCAdd Upper Imm. to PCYYYAUIPC rd,imm

Logical

InstructionNameRV32IRV64IRV128ISyntax
XORXORYYYXOR rd,rs1,rs2
XORIXOR ImmediateYYYXORI rd,rs1,imm
ORORYYYOR rd,rs1,rs2
ORIOR ImmediateYYYORI rd,rs1,imm
ANDANDYYYAND rd,rs1,rs2
ANDIAND ImmediateYYYANDI rd,rs1,imm

Compare

InstructionNameRV32IRV64IRV128ISyntax
SLTSet <YYYSLT rd,rs1,rs2
SLTISet < ImmediateYYYSLTI rd,rs1,imm
SLTUSet < UnsignedYYYSLTU rd,rs1,imm
SLTIUSet < Immediate UnsignedYYYSLTIU rd,rs1,imm

Branches

InstructionNameRV32IRV64IRV128ISyntax
BEQBranch Equal YYYBEQ rs1,rs2,imm
BNEBranch Not EqualYYYBNE rs1,rs2,imm
BLTBranch Less ThanYYYBLT rs1,rs2,imm
BGEBranch Greater ThanYYYBGE rs1,rs2,imm
BLTUBranch Less ThanYYYBLTU rs1,rs2,imm
BGEUBranch Greater ThanYYYBGEU rs1,rs2,imm

Jump & Link

InstructionNameRV32IRV64IRV128ISyntax
JALJump And LinkYYYJAL rd,imm
JALRJump And Link RegisterYYYJALR rd,rs1,imm

Sync

InstructionNameRV32IRV64IRV128ISyntax
FENCESync ThreadYYYFENCE
FENCE.ISync Instruction & DataYYYFENCE.I

System

InstructionNameRV32IRV64IRV128ISyntax
SCALLSystem CALLYYYSCALL
SBREAKSystem BREAKYYYSBREAK

Counters

InstructionNameRV32IRV64IRV128ISyntax
RDCYCLEReaD CYCLEYYYRDCYCLE rd
RDCYCLEHReaD CYCLE upper HalfYYYRDCYCLEH rd
RDTIMEReaD TIMEYYYRDTIME rd
RDTIMEHReaD TIME upper HalfYYYRDTIMEH rd
RDINSTRETReaD INSTR RetiredYYYRDINSTRET rd
RDINSTRETHReaD INSTR Retired upper HalfYYYRDINSTRETH rd

Pseudo-instructions

The RISCV specification also dictates several Pseudo Instructions. These aren't implemented in hardware, but are translated by the assembler to common tasks.

Loads

InstructionNameActionsRV32IRV64IRV128ISyntax
LALoad AddressAUIPC rd, symbol[31:12]
ADDI rd, rd, symbol[11:0]
YYYLA rd, symbol
NOPNo OperationADDI x0, x0, 0YYYNOP
LILoad ImmediateVariesYYYLI rd, immediate
MVMove (Copy) RegisterADDI rd, rs, 0YYYMV rd, rs
SEXT.WSign Extend WordADDIW rd, rs, 0YYYSEXT.W rd, rs

Branches

InstructionNameActionsRV32IRV64IRV128ISyntax
BEQZBranch If Equal ZeroBEQ rs, x0, offsetYYYBEQZ rs, offset
BNEZBranch If Not Equal ZeroBNE rs, x0, offsetYYYBNEZ rs, offset
BLEZBranch If Less Than or Equal ZeroBGE x0, rs, offsetYYYBLEZ rs, offset
BGEZBranch If Greater Than or Equal ZeroBGE x0, rs, offsetYYYBLEZ rs, offset
BLTZBranch If Less Than ZeroBLT rs, x0, offsetYYYBLTZ rs, offset
BGTZBranch If Greater Than ZeroBLT x0, rs, offsetYYYBGTZ rs, offset
BGTBranch If Greater ThanBLT rt, rs, offsetYYYBGT rs, rt, offset
BLEBranch If Less Than or EqualBGE rt, rs, offsetYYYBLE rs, rt, offset
BGTUBranch If Greater Than, UnsignedBLTU rt, rs, offsetYYYBGTU rs, rt, offset
BLEUBranch If Greater Than or Equal, UnsignedBGEU rt, rs, offsetYYYBLEU rs, rt, offset

Compare

InstructionNameActionsRV32IRV64IRV128ISyntax
SEQZSet If Equal ZeroSLTIU rd, rs, 1YYYSEQZ rd, rs
SNEZSet If Not Equal ZeroSLTU rd, x0, rsYYYSNEZ rd, rs
SLTZSet If Less Than ZeroSLT rd, rs, x0YYYSLTZ rd, rs
SGTZSet If Greater Than ZeroSLT rd, x0, rsYYYSGTZ rd, rs

Counters

InstructionNameActionsRV32IRV64IRV128ISyntax
RDCYCLERead Cycle CounterCSRRS rd, cycle[h], x0YYYRDCYCLE[h] rd
RDTIMERead Real-Time ClockCSRRS rd, time[h], x0YYYRDTIME[h] rd
RDINSTRETRead Instruction Retired CounterCSRRS rd, instret[h], x0YYYRDINSTRET[h] rd

Jump & Link

InstructionNameActionsRV32IRV64IRV128ISyntax
JJump (Near, Non-returnable)JAL x0, offsetYYYJ offset
JALJump And Link (Near, Returnable)JAL x1, offsetYYYJAL offset
JRJump RegisterJALR x0, rs, 0YYYJALR rs
JALRJump And Link RegisterJALR x1, rs, 0YYYJALR rs
RETReturn From SubroutineJALR x0, x1, 0YYYRET
CALLCall Subroutine (Far, Returnable)AUIPC x6, offset[31:12]
JALR x1, x6, offset[11:0]
YYYCALL offset
TAILTail Call Subroutine (Far, Non-returnable)AUIPC x6, offset[31:12]
JALR x0, x6, offset[11:0]
YYYTAIL offset

Logical

InstructionNameActionsRV32IRV64IRV128ISyntax
NOTOne's ComplementXORI rd, rs, -1YYYNOT rd, rs
NEGTwo's ComplementSUB rd, x0, rsYYYNEG rd, rs
NEGWTwo's Complement WordSUBW rd, x0, rsYYYNEGW rd, rs

Sync

InstructionNameActionsRV32IRV64IRV128ISyntax
FENCEFence on all memory and I/OFENCE iorw, iorwYYYFENCE

TODO

InstructionNameActionsRV32IRV64IRV128ISyntax
CSRRCSR ReadCSRRS rd, csr, x0YYYCSRR rd, csr
CSRWCSR WriteCSRRW x0, csr, rsYYYCSRW csr, rs
CSRSCSR Set BitsCSRRS x0, csr, rsYYYCSRS csr, rs
CSRCCSR Clear BitsCSRRC x0, csr, rsYYYCSRC csr, rs
CSRWICSR Write ImmediateCSRRWI x0, csr, immYYYCSRWI csr, imm
CSRSICSR Set Bits ImmediateCSRRSI x0, csr, immYYYCSRSI csr, imm
CSRCICSR Clear Bits ImmediateCSRRCI x0, csr, immYYYCSRCI csr, imm