Course: Computer Architectures
Lecture summary
Begin with the operations a processor exposes to software, then follow how instructions represent operands and choose the next instruction.
Start with the interface between software and the processor. An instruction set defines the operations a program can request and the state those operations can access. RISC-V provides the vocabulary used in these notes; it does not prescribe one particular pipeline implementation. RISC-V
Instructions need operands. Registers hold values the processor can use directly, while immediates encode constants inside instructions. The width and signed interpretation of an immediate constrain which constants fit in one instruction, explaining why larger values sometimes require a sequence. Registers and Immediates
Functions explain one form of control transfer, but conditions and loops also need to choose what executes next. A branch changes the program counter when its condition is true; otherwise execution continues sequentially. A jump transfers control without that conditional test. Branches
The detailed notes below retain the lecture’s examples, timing diagrams or comparisons, and source references. Continue afterward with Lecture 02 - Memory, Stack and Function Calls.
Topics
What to remember from this lecture
RISC-V instructions use fixed operand formats. Registers hold full machine-word values, while immediates are constants encoded directly inside instructions.
Useful register facts:
x0 = always 0
x1 = ra
x2 = spThe ABI names such as ra and sp are aliases for numbered registers.
Immediate instructions
addi rd, rs1, immmeans:
rd = rs1 + immFor addi, the immediate is signed and 12 bits wide.
Small constants can therefore be loaded with:
addi rd, x0, immThe pseudo-instruction:
li rd, valuelets the assembler choose the real instruction sequence needed.
For larger values, this may require lui and addi.
lui
lui rd, imm20places the immediate in bits 31:12 and makes the lower 12 bits zero.
Example:
lui x5, 0x12345produces:
0x12345000Signed lower-immediate issue
A 12-bit immediate with bit pattern 0x800 represents -2048.
Therefore loading 0x1800 can use:
lui x5, 0x2
addi x5, x5, -0x800because:
0x2000 - 0x0800 = 0x1800ALU instructions covered
Shift left
sll x3, x2, x1
slli x3, x2, 4sll: shift amount comes from a register.slli: shift amount is an immediate.
Set less than immediate
slti x3, x2, 4sets x3 to 1 if x2 < 4, otherwise 0.
Zero tests
seqz x3, x2
snez x3, x2seqz: set to 1 if source is zero.snez: set to 1 if source is nonzero.
Branch basics
Branches are conditional jumps.
Common instructions:
beq equal
bne not equal
blt signed less-than
bge signed greater-or-equal
bltu unsigned less-than
bgeu unsigned greater-or-equalSigned and unsigned comparisons use the same register bits but interpret them differently.
Questions to review
- Why is the immediate in
addirestricted? - Why can
0x800mean-2048? - Why can
liexpand to multiple instructions? - What changes between
bltandbltu?