Lecture 7 Intro to RISC-V¶
Assembly Language¶
- Different CPU implement different sets of instructions.
- The set of instructions a particular CPU implements is an ISA (Instructions Set Architecture).
Examples of ISAs
- ARM (cell phones)
- Intel x86 (i9, i7, i5, i3)
- IBM/Motorola PowerPC (old Macs)
- MIPS
- RISC-V
RISC philosophy
- RISC: Reduced Instruction Set Computer
- Keep the instruction set small and simple, makes it easier to build fast hardware
RISC-V¶
- Assembly Operands are registers
- Registers are limited number of special locations, built directly into the hardware
- RISC-V: Operations can only be performed on register operands
- In Assembly Language, there's no type for registers
- Register contents are just bits
- Operation determines type, i.e., how register contents are treated
Since registers are inside the processor and directly into the hardware, it's super fast.
32 Registers in RISC-V¶
RISC-V code must be very carefully put together to efficiently use registers
- Each RISC-V register is 32 bits wide.
- Groups of 32 bits called a word
- Referred to by number x0 – x31
- x0 is always 0
- only 31 registers able to hold variable values
Syntax Presentation in RISC-V¶
- Each statement is an instruction
- Each line of assembly code contains at most 1 instruction
- Syntax is rigid
- 1 Operator
- 3 Operands
format:
C | |
---|---|
1 2 3 4 5 6 |
|
In-line comments prefixed by #
, no multi-line comment support:
Text Only | |
---|---|
1 2 3 |
|
Basic¶
add / sub / addi / subi(X)
(1) add:
Text Only | |
---|---|
1 |
|
(2) sub:
Text Only | |
---|---|
1 |
|
(3) addi:
Text Only | |
---|---|
1 2 3 4 |
|
(4) subi(X):
There is no
subi
in RISC-V, but we can use (addi
+ negative number) to implementsubi
:
Text Only | |
---|---|
1 |
|
(5) RISC-V hardwires the register x0
to value 0:
Text Only | |
---|---|
1 2 3 4 |
|
Here we can find x0 is still 0, the last instruction will do nothing :)