




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































[Weatherspoon, Bala, Bracy, McKee and Sirer]
Write- Memory Back
Instruction Fetch
Instruction Execute Decode
extend
register file
control
alu
memory
din dout
addr PC
memory
new pc
inst
IF/ID (^) ID/EX EX/MEM MEM/WB
imm
ctrl ctrl ctrl
jump/branch^ compute targets
Forward unit Detect hazard
Big Picture: Where are we going?
SandyBridge Motherboard, 2011 http://news.softpedia.com 4
CPU
Main Memory (DRAM)
Big Picture: Where are we going?
Calling Convention for Procedure Calls
Enable code to be reused by allowing code
snippets to be invoked
Will need a way to
Write- Memory Back
Instruction Fetch
Instruction Execute Decode
extend
register file
control
alu
memory
din dout
addr PC
memory
new pc
inst
IF/ID (^) ID/EX EX/MEM MEM/WB
imm
ctrl ctrl ctrl
jump/branch^ compute targets
Cheat Sheet and Mental Model for Today
Forward unit Detect hazard
How do we share registers and use memory when making procedure calls?
Cheat Sheet and Mental Model for Today
saved ra saved fp saved regs (s1 ... s11)
locals
incoming args
x0 zero zero x1 ra return address x2 sp stack pointer x3 gp global data pointer x4 tp thread pointer x5 t0 (^) temps x6 x7 t1t2 (caller save)
x8 s0/fp frame pointer x9 s1 saved (callee save) x10 a0 function args or x11 a1 return values x12 a function x13 a3 arguments x14 a
x15 a function arguments
x16 a x17 a x18 s
saved (callee save)
x19 s x20 s x21 s x22 s x23 s x24 s x25 s x26 s x27 s x28 t temps (caller save)
x29 t x30 t
Transfer Control
Calling Convention for Procedure Calls
11
Jumps are not enough
main: j myfn after1: add x1,x2,x
myfn: …
j after
Jumps to the callee
Jumps back
Jumps are not enough
main: j myfn after1: add x1,x2,x
j myfn after2: sub x3,x4,x
myfn: …
j after
Jumps to the callee
Jumps back
What about multiple sites?
??? Change target on the fly ???
j after
Jump-and-Link / Jump Register
main: jal myfn after1: add x1,x2,x
jal myfn after2: sub x3,x4,x
myfn: …
jr x
JAL saves the PC in register $
Subroutine returns by jumping to $
First call x1 (^) after
after
Jump-and-Link / Jump Register
main: jal myfn after1: add x1,x2,x
jal myfn after2: sub x3,x4,x
myfn: …
jr x
JAL saves the PC in register x
Subroutine returns by jumping to x
What happens for recursive invocations?
Second call x1 (^) after
int main (int argc, char* argv[ ]) {
int n = 9; int result = myfn(n);
}
int myfn(int n) {
if(n > 0) { return n * myfn(n - 1); } else { return 1; } }
JAL / JR for Recursion?
JAL / JR for Recursion?
main: jal myfn after1: add x1,x2,x
myfn: if ( test ) jal myfn after2:
jr x
Problems with recursion:
First call x1 (^) after