Mechanisms ECE 3035
Popular in Course
Popular in ELECTRICAL AND COMPUTER ENGINEERING
This 0 page Class Notes was uploaded by Cassidy Effertz on Monday November 2, 2015. The Class Notes belongs to ECE 3035 at Georgia Institute of Technology - Main Campus taught by Staff in Fall. Since its upload, it has received 30 views. For similar materials see /class/233924/ece-3035-georgia-institute-of-technology-main-campus in ELECTRICAL AND COMPUTER ENGINEERING at Georgia Institute of Technology - Main Campus.
Reviews for Mechanisms
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 11/02/15
Review of Activation Frames In general activation frames are organized like this HI Bookkeepingpreserved RA of caller registers FP of caller Y Caller s responsibility IO 1 X Return value A Locals and temps B Callee s responsibility C LO Consider the following function int Fooint a int b int x int y 10 x ayb return x This problem writes the MIPS code to implement Foo in parts The beginning of Foo s activation frame is shown on the stack This is the state as Foo is called FP gt Caller of Foo s AF ends here Foo s AF starts Return LO Part A Write MIPS code to complete Foo s activation frame by pushing locals on the stack Be sure to update the frame pointer properly Answers are in bold face Foo FP 8 alloc 2 ints x SW Part B Compute the X ayb statement by accessing a y and b from the stack Be sure to Suppose we have a function Fun which calls another function AppleFun with 2 args iht Fuhiht l int x y Z Result Result AppleFuhl J l J returh Result Part of the MIPS implementation of Fun is given below Part A Fill in the MIPS code necessary before the call to AppleFun You will need to prepare the stack and preserve registers that are needed after the function call Part B Write the MIPS code to restore the values from AppleFun s activation frame and assign the value of Result assume Fuh s locals are allocated in its AF Fuh assume Result is allocated at offset l6 relative to Fuh s FP assume l 1 2 J 2 2 add 6 1 2 6 IJ addi 29 29 24 SW 31 2029 The Answer to PART A goes in these slots Determine SW 30 1629 what should be preserved SW 6 1229 31 30 6 allocate SW 392 829 IO params sw 1 429 jal AppleFuh 1W 31 2029 1W 30 1629 The Answer to PART B goes 1W 6 1229 in these slots Restore 1W 393 029 preserved values and update add 29 29 24 Result add 6 3 6 sw 6 1630 deallocate Fuh s locals jr 3l returh Now suppose Fun calls BerryFun which is a function of 2 pointers to integers iht iht iht iht R BerryFuhiht A B C D Fuhiht lJ esult BerryFuhampC ampD Suppose C and D are statically de ned at addresses 5000 and 5004 respectively Fill in tl e MIPS code to 39 39 this fL nction call Fuh assume Fuh s locals are allocated in its AF assume Result is allocated at offset l6 relative to Fuh s FP Z Z assume l 1 2 J addi 29 29 20 SW 31 1629 The Answer to PART A goes in these sw 30 1229 slots Determine what should be addi 1 0 5004 preserved 31 30 allocate sw 1 829 IO params Note that the inputs addi 1 0 5000 are addresses of C and D sw 1 429 jal BerryFuh lw 31 1629 I 1W 30 1229 The Answer to PART B goes in these 1W 3 029 slots Restore preserved values and update Result sw 3 1630 u deallocate Fuh s locals jr 3l returh Function pointer example int search int a int b int ascending E extremea b ascending maximum minimum int extremeint x int y int compareint int if compareHx y result x else result y Suppose the functions maximum and minimum are de ned at locations 4600 and 4700 respectively The current state of the stack at the beginning of search looks like this RA Search s locals