Procedure cal and Array
1 Procedure Call and Array
Outline Data manipulation Control structure Suggested reading -chap3.7,3.8
2 Outline • Data manipulation • Control structure • Suggested reading – Chap 3.7, 3.8
Procedure In high level programming languages Parameter passing(actual vs formal) Return value Control transfer Allocate space for local variables on entry Deallocate space for local variables on exit
3 Procedure • In high level programming languages – Parameter passing (actual vs. formal) – Return value – Control transfer – Allocate space for local variables on entry – Deallocate space for local variables on exit
Procedure implementation Stack frame a fixed register is used to hold the return value Simple instructions for control transferring Reqister usage Calling convention Convention:约定 Frame:帧,结构
4 Procedure Implementation • Stack frame • A fixed register is used to hold the return value • Simple instructions for control transferring • Register usage • Calling convention Convention:约定 Frame: 帧,结构
Call Chain Stack Frames Main A BO CO BO CO A(;
5 Call Chain & Stack Frames Main { C(); A() ; } A() { B() ; } B() { C() ; }
Call Chain Stack Frames Main A BO Stack frame for maino CO BO CO A(;
6 Call Chain & Stack Frames Main { C(); A() ; } A() { B() ; } B() { C() ; } Stack frame for main()
Call Chain Stack Frames Main A BO Stack frame for maino CO BO CO Stack frame for CO A(;
7 Call Chain & Stack Frames Main { C(); A() ; } A() { B() ; } B() { C() ; } Stack frame for main() Stack frame for C()
Call Chain Stack Frames Main A BO Stack frame for maino CO BO CO Stack frame for AO A(;
8 Call Chain & Stack Frames Main { C(); A() ; } A() { B() ; } B() { C() ; } Stack frame for main() Stack frame for A()
Call Chain Stack Frames Main A BO Stack frame for maino CO BO CO Stack frame for A( A(; Stack frame for BO
9 Call Chain & Stack Frames Main { C(); A() ; } A() { B() ; } B() { C() ; } Stack frame for main() Stack frame for A() Stack frame for B()
Call Chain Stack Frames ain A BO Stack frame for maino CO BO CO Stack frame for AO A(; Stack frame for BO Stack frame for CO
10 Call Chain & Stack Frames Main { C(); A() ; } A() { B() ; } B() { C() ; } Stack frame for main() Stack frame for A() Stack frame for B() Stack frame for C()