Chap2 RISC5 ISA
Chap2 RISC5 ISA
Chap2 RISC5 ISA
Chapter 2
Instructions: Language of the Computer
SANTA CLARA UNIVERSITY
Instruction Set
ISA Overview
• Instructions: 32-bits (8 bits = 1byte)
• Instructions are aligned in memory (must start at location divisible by 4).
• Number of (gp) Registers: 32. (X0..X31), X0 ≡ 0 (inside the CPU)
• Each register is 32-bits wide & register 0 is hardwired (fixed) to the value 0.
• Memory is byte-addressable
• Data address is the address of the lowest byte of the data item.
• Data does not have to be aligned in memory (can start at any address).
• Data Aligned means address A of data is multiple of S (size of data).
• Data is stored in a little-endian manner (Endianness??)
• That means the least significant byte of a word in stored in the lowest address of the word.
• Example: integer 0x00112233 at location 80 is stored as
80 81 82 83
Little-Endian 33 22 11 00
Big Endian 00 11 22 33
Assembly Instructions
4/21/2022
SANTA CLARA UNIVERSITY
4/21/2022
SANTA CLARA UNIVERSITY
4/21/2022
SANTA CLARA UNIVERSITY
4/21/2022
SANTA CLARA UNIVERSITY
lhu 1 0 1
4/21/2022
SANTA CLARA UNIVERSITY
Func3[2:0]
Immed[11:5] Rs2[4:0] Rs1[4:0] Immed[4:0] Opcode[6:0](decimal)
(binary)
sb 0 0 0 Lower 5 bits
Source register Source register 35
sh Upper 7 bits of 12-bit 0 0 1 of 12-bit 2’s
for data to copy (part of address (same opcode shared
2’s complement offset complement
sw to memory calculation) 0 1 0 by all load variants)
offset
4/21/2022
SANTA CLARA UNIVERSITY
4/21/2022
SANTA CLARA UNIVERSITY
4/21/2022
SANTA CLARA UNIVERSITY
Func* Fields
4/21/2022
SANTA CLARA UNIVERSITY
lw x3,4(x2); load g
lw x4, 8(x2); load h
lw x5, 12(x2); load i
lw x6, 16(x2); load j
add x7, x3, x4; t0=g + h
add x8, x5, x6; t1=i + j
sub x7, x7, x8; t0= t0-t1
sw x7, 0(x2); store f
Chapter 2 — Instructions: Language of the
Computer — 16
SANTA CLARA UNIVERSITY
• C code:
A[12] = h + A[8];
• h in x21, base address of A in x22
• Compiled RISC-V code
• Assuming h and address of A[0] are already in registers
lw x9, 32(x22); Index 8 requires offset of 32
add x9, x21, x9
sw x9, 48(x22); Index 12 requires offset of 48
Shift Operations
funct6 immed rs1 funct3 rd Opcode =19
6 bits 6 bits 5 bits 3 bits 5 bits 7 bits
Conditional Operations
• Branch to a labeled instruction if a condition is true
• Otherwise, continue sequentially
The assembler will take the leftmost 12 bits and pack them in
instruction binary representation.
4/21/2022
SANTA CLARA UNIVERSITY
4/21/2022
SANTA CLARA UNIVERSITY
Jump Addressing
• Jump and link (jal) target uses 21-bit immediate for
larger range
• UJ format:
imm[10:1] imm[19:12] rd opcode
5 bits 7 bits
imm[20] imm[11]
Concluding Remarks
• Design principles
1. Simplicity favors regularity
2. Smaller is faster
3. Good design demands good compromises
• Make the common case fast
• Layers of software/hardware
• Compiler, assembler, hardware
• RISC-V: typical of RISC ISAs
• c.f. x86