






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!







Spring 2003 CS 403 Class Notes (^) Page 1
Spring 2003 CS 403 Class Notes (^) Page 3
IP contains an integer which gives location of current instruction
data for foo
Return address
params
Local vars
data for main
Return address
params
Local vars
Spring 2003 CS 403 Class Notes (^) Page 7
void foo(int x, int y){ int a; y++; a = y; }
void main(void){ int x = 3; int y = 2; foo(x, y); x++; }
Code for foo: INC 5003 SV 5004, 5003 J *
Code for main: SC 3002, 3 SC 3003, 2 SV 5002, 3002 SV 5003, 3003 SA 5000, 1009 J 1000 INC 3002
BOM = 3000 BOF = 5000 BOC = 1000
Spring 2003 CS 403 Class Notes (^) Page 9
Stack Memory: Special Registers
record.
available for a new activation record.
loader:
Extension to Assembly Language
Spring 2003 CS 403 Class Notes (^) Page 13
void bar(int y){ y++; }
void foo(int x){ bar(x); x++; }
void main(void){ int x = 2; foo(x); x++; }
void foo(int x, int & y){ int a; y++; a = y; }
void main(void){ int x = 3; int y = 2; foo(x, y); x++; }
Code for foo: INC *( FP+4 ) SV FP+5, FP+ J *(FP+1)
Code for main: SC FP+3, 3 -- main[3] = 3 SC FP+4, 2 -- main[4] = 2 SA SP, FP -- foo[0] = &main[0] SR FP, SP -- fp = sp SR SP, SP+6 -- sp = sp + 6 SV FP+3, *FP+3 -- foo[3] = main[3] SA FP+4, *FP+4 -- foo[4] = main[4] SA FP+1, BOC+12 -- foo[1] = code[12] J BOC -- jump to code[0] SR SP, FP -- sp = fp SR FP, *FP -- fp = &main[0] INC FP+3 -- main[3]++
Spring 2003 CS 403 Class Notes (^) Page 15
void foo(int x, int & y){ int a; y++; a = y; }
void main(void){ int x = 3; int y = 2; foo(x, y); x++; }
Code for main: SC FP+3, 3 -- main[3] = 3 SC FP+4, 2 -- main[4] = 2 SA SP, FP -- foo[0] = &main[0] SR FP, SP -- fp = sp SR SP, SP+6 -- sp = sp + 6 SV FP+3, *FP+3 -- foo[3] = main[3] SA FP+4, *FP+4 -- foo[4] = main[4] SA FP+1, 2012 -- foo[1] = code[12] J 2000 -- jump to code[0] SR SP, FP -- sp = fp SR FP, *FP -- fp = &main[0] INC FP+3 -- main[3]++
Spring 2003 CS 403 Class Notes (^) Page 19
foo static data segment
return addresses
return addresses
int foo(int x, int y){ int a; y++; a = y; return a; }
void main(void){ int x = 3; int y = 2; int b = foo(x, y); x++; }
Assembly code: Code for foo: INC FP+ SV FP+5, FP+ SV FP+2, FP+ J *(FP+1)
Code for main: SC FP+3, 3 -- main[3] = 3 SC FP+4, 2 -- main[4] = 2 SA SP, FP -- foo[0] = &main[0] SR FP, SP -- fp = sp SR SP, SP+6 -- sp = sp + 6 SV FP+3, *FP+3 -- foo[3] = main[3] SV FP+4, *FP+4 -- foo[4] = main[4] SA FP+1, BOC+12 -- foo[1] = code[12] J BOC -- jump to code[0] SR SP, FP -- sp = fp SR FP, *FP -- fp = &main[0] SV FP+5, SP+2 -- main[5] = foo[2] INC FP+3 -- main[3]++
Spring 2003 CS 403 Class Notes (^) Page 21
int foo(int x, int y){ int a; y++; a = y; return a; }
void main(void){ int x = 3; int y = 2; int b = foo(x, y); x++; }
Assembly code: Code for foo: INC FP+4 BOC = 2000 SV FP+5, FP+ SV FP+2, FP+ J *(FP+1)
Code for main: SC FP+3, 3 -- main[3] = 3 SC FP+4, 2 -- main[4] = 2 SA SP, FP -- foo[0] = &main[0] SR FP, SP -- fp = sp SR SP, SP+6 -- sp = sp + 6 SV FP+3, *FP+3 -- foo[3] = main[3] SV FP+4, *FP+4 -- foo[4] = main[4] SA FP+1, 2012 -- foo[1] = code[12] J 2000 -- jump to code[0] SR SP, FP -- sp = fp SR FP, *FP -- fp = &main[0] SV FP+5, SP+2 -- main[5] = foo[2] INC FP+3 -- main[3]++