Professional Documents
Culture Documents
RISC-V
Reminders:
- Lab 1 released today
- Lab hours begin tomorrow
- Sign up for piazza
- Lecture questions due by 10 AM
Direct
Hardware
Microprocessor Execution
x0 Address 31 0
x1 100110....0 0
4
x2
8 Holds
32-bit “words” 12 program
...
16
20
and data
x31
32-bit “words”
ALU
Arithmetic Machine language directly
Logic Unit reflects this structure
February 18, 2021 MIT 6.004 Spring 2021 L02-3
MicroProcessor Structure /
Assembly Language
§ Each register is of fixed size, say 32 bits
§ The number of registers are small, say 32
§ ALU directly performs operations on the register
file, typically
§ xi ¬ Op( xj , xk ) where Op Î {+, AND, OR, <, >, ...}
§ Memory is large, say Giga bytes, and holds
program and data
§ Data can be moved back and forth between
Memory and Register File using load and store
instructions
x4 ß load(Mem[x1]) 0
x1 Addr of a[i] 4 a[0]
add x3, x3, x4 n
x2 8 a[1]
addi x1, x1, 4 x3 sum
addi x2, x2, -1 a[n-1]
bnez x2, loop x10 100
100 base
104 n
store(sum) ß x3 108 sum
Base 10 Base 2
111
5 00101
+ 3 + 00011
8 0 1 0 00
§ sll x3, x1, x2 00101
Shift x1 left 01010 Notice fixed
by x2 bits 10100 width
01000
0x0
x3 ß x1 + x2 0x4 b
0x8 c
a: store(Mem[0x10]) ß x3 0xC
0x10 a
0x14
32-bit “words”
(4 bytes)
§ Assembly: § Behavior:
Main Memory
lw ß
x1 x1,load(base)
0x0(x10)
lw ß
x2 x2,load(n)
0x4(x10) Register File 31 0
addßx3,
x3 0 x0, x0 0
x1 Addr of a[i] 4 a[0]
loop: n
x2 8 a[1]
lw ß
x4 x4,load(Mem[x1])
0x0(x1) x3 sum
add x3, x3, x4 a[n-1]
addi
addi x1,
x1, x1,
x1, 44 x10 100
100 base
addi
addi x2,
x2, x2,
x2, -1
-1 n
104
bnez
bnez x2,
x2, loop
loop 108 sum
store(sum) ß x3
sw x3, 0x8(x10)
February 18, 2021 MIT 6.004 Spring 2021 L02-23
Pseudoinstructions
§ Aliases to other actual instructions to simplify
assembly programming.
Next lecture:
Implementing Procedures in Assembly