Risc V
Risc V
Risc V
CASS 2018
Lavanya Ramapantulu
Program
• Program = ??
add x6,x10,x6
C-like code
"Assembly" Code
fragment
Source acknowledgement: http://www.comp.nus.edu.sg/~cs2100/lect/cs2100-9-MIPS-1-full.pptx
3-Jul-18 CASS18 - ISA and RISCV 7
Recap: Computer Components
• What are the two major components in a
computer
Memory
Processor
Bus
Perform Bridge between the two
components
computation
Storage of code
and data
………..
………..
………..
………..
………..
………..
………..
………..
………..
………..
C = A+B
Memory
Data n-bit data bus :
Register
Control lines
(R/W, etc.)
• Instruction Length
• Instruction Fields
– Type and Size of Operands
Concept #1: Data Storage
Concept #2: Memory Addressing Modes
Concept #3: Operations in the Instruction Set
Concept #4: Instruction Formats
Concept #5: Encoding the Instruction Set
• Instruction Encoding
• Encoding for Fixed-Length Instructions
First Attempt:
Fixed length Opcode
opcode operand
Type-B 11 bits 5 bits
Questions:
How do we distinguish between Type-A and Type-B?
How many different instructions do we really have?
Source acknowledgement: http://www.comp.nus.edu.sg/~cs2100/lect/cs2100-13b-ISA.pptx
3-Jul-18 CASS18 - ISA and RISCV 42
Fixed Length Instruction: Encoding (4/4)
• What is the maximum number of instructions?
opcode operand operand Answer:
Type-A 6 bits 5 bits 5 bits 1 + (26 –1) 25
opcode operand = 1 + 6332
Type-B 11 bits 5 bits = 2017
Reasoning:
1. For every 6-bit prefix (front-part) given to Type-B, we get 25 unique
patterns, e.g. [111111]XXXXX
2. So, we should minimize Type-A instruction and give as many 6-bit
prefixes as possible to Type-B
1 Type-A instruction, 26-1 prefixes for Type-B
Source acknowledgement: http://www.comp.nus.edu.sg/~cs2100/lect/cs2100-13b-ISA.pptx
3-Jul-18 CASS18 - ISA and RISCV 43
Why RISC-V
• Open and free
• Not domain-specific
• No baggage of legacy
• Instruction fields
– opcode: operation code
– rd: destination register number
– funct3: 3-bit function code (additional opcode)
– rs1: the first source register number
– rs2: the second source register number
– funct7: 7-bit function code (additional opcode)
0 21 20 0 9 51
• NOP ?
imm[12] imm[11]
PC-relative addressing
Target address = PC + immediate × 2
3-Jul-18 CASS18 - ISA and RISCV 64
Jump Addressing
• Jump and link (jal) target uses 20-bit
immediate for larger range
• UJ format:
imm[10:1] imm[19:12] rd opcode
5 bits 7 bits
imm[20] imm[11]