Professional Documents
Culture Documents
Compiling Code, and Implementing Procedures: February 23, 2021 MIT 6.004 Spring 2021 L03-1
Compiling Code, and Implementing Procedures: February 23, 2021 MIT 6.004 Spring 2021 L03-1
Implementing Procedures
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 23, 2021 MIT 6.004 Spring 2021 L03-3
Registers vs Memory
add x1, x2, x3
x1 = 0x1C
mv x4, x3 Main Memory
x4 = 0x14 Address
Register File 31 0
lw x5, 0(x3)
0x0 0x35
x5 = 0x23 x1 0x1C 0x4 0x3
x2 0x8 0x8 0x9
lw x6, 8(x3)
x3 0x14 0xC 0x1
x6 = 0x16 0x14 0x10 0x22
x4
sw x6, 0xC(x3) 0x23 0x14 0x23
x5
0x16 0x18 0x21
value of x6 (0x16) x6
0x1C 0x16
is written to M[0x14+0xC] 0x20 0x18
0x16
Next lecture:
Procedures, Stacks, and MMIO