Professional Documents
Culture Documents
Muhammad Tahir
Lecture 3
Contents
1 RISC-V ISA
5 Control Instructions
2/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
Competing ISAs
3/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
RISC-V ISA
4/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
5/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
6/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
RV32I Registers
• General Purpose Registers (GPRs) (32 registers)
• x0, x1, ..., x31
• 32-bit wide integer registers
• x0 is hard-wired to zero
• Control and Status Registers (CSRs)
• User Level CSRs
• Supervisor Level CSRs
• Hypervisor Level CSRs
• Machine Level CSRs
7/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
8/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
8/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
8/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
Compare Branch
Instructions Instructions
SLT, SLTU, SLTI, SLTIU BEQ, BNE, BLT, BGE
BLTU, BGEU
Other
Instructions Control and Status
Register (CSR)
Synch
CSRRW, CSRRS, CSRRC,
Instructions
CSRRWI,CSRRSI, CSRRCI
FENCE, FENCE.I
Jump & Link
Instructions
Environment
Instructions JAL, JALR
ECALL, EBREAK
Trap/Interrupt
Instructions
9/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• I Format
imm[11:0] rs1 func3 rd opcode
• S Format
imm[11:5] rs2 rs1 func3 imm[4:0] opcode
• U Format
imm[31:12] rd opcode
10/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Similar to S Format
• S Format
imm[11:5] rs2 rs1 func3 imm[4:0] opcode
• B Format
imm[12:10:5] rs2 rs1 func3 imm[4:1:11] opcode
11/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Similar to U Format
• U Format
imm[31:12] rd opcode
• J Format
imm[20]:imm[10:1]:imm[11]:imm[19:12] rd opcode
12/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
13/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: R-type
7 5 5 3 5 7
func7 rs2 rs1 func3 rd opcode
14/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
15/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: I-type
7 : 5 5 3 5 7
imm[11:5] : imm[4:0] rs1 func3 rd opcode
16/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
17/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: I-type
12 5 3 5 7
imm[11:0] rs1 func3 rd opcode
18/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: I-type
12 5 3 5 7
imm[11:0] rs1 func3 rd opcode
• I-imm = signExtend(imm[11:0])
• opcode = LOAD: rd ← mem[rs1 + I-imm]
• funct3 = LW/LB/LBU/LH/LHU
19/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: S-type
7 5 5 3 5 7
imm[11:5] rs2 rs1 func3 imm[4:0] opcode
20/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: S-type
7 5 5 3 5 7
imm[11:5] rs2 rs1 func3 imm[4:0] opcode
21/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
22/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• I-imm = signExtend(imm[11:0])
• opcode = JALR: rd ← pc + 4;
∼
pc ← ((rs1 + I-imm) & (0x01))
24/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
25/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
• Format: B-type
1 : 6 5 5 3 4 : 1 7
imm[12:10:5] rs2 rs1 func3 imm[4:1:11] opcode
26/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
Suggested Reading
• Read User Manual for the instruction set and its architecture
[Waterman et al., 2016b].
• For Control and Status register description consult Privileged
architecture manual [Waterman et al., 2016a].
27/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
Acknowledgment
28/29
RISC-V ISA RISC-V Instruction Formats Data Processing Instructions Memory Access Instructions Control Instructions
References
Waterman, A., Lee, Y., Avizienis, R., Patterson, D. A., and Asanovic, K.
(2016a).
The risc-v instruction set manual volume ii: Privileged architecture version
1.9.
EECS Department, University of California, Berkeley, Tech. Rep.
UCB/EECS-2016-129.
29/29