CS453 Colorado State University ============================================== Functions and Function Calls cont ... ============================================== What goes up must come down. Compilers analog. What is pushed, must be popped. ------------------------- Plan for today Function call AVR example ------------------------- Function Call AVR example Goals - understand the calling convention for avr-gcc - see how constant expression evaluation at compile time interacts with run-time expression evaluation - storing and accessing parameters - handling two-byte types - show off some new MJSIM.jar functionality - see an example of the kinds of questions you will be expected to answer on the final Example: PA5funcexample.java and PA5funcexample.java.s ------------------------ Example questions for PA5funcexample.java (1) What does the run-time stack look like right before the call to haste(1,2,3,4,5,6,2) returns? Indicate where the frame pointer and stack pointer are pointing right before the ret instruction executes. (2) If the calling convention changes so that parameters are passed right to left on the stack, the callee is responsible for popping parameters, and the return value stays in r25:r24, what would the run-time stack look like at the very beginning of the callee for the haste(1,2,3,4,5,6,7,8) call? (3) Describe one other way we can store parameter values within the callee and still satisfy the avr-gcc calling convention. (4) Modify the PA5funcexample.java and PA5funcexample.java.s so that if the haste() function does not store and restore the callee-saved registers then the AVR program would execute incorrectly. (5) When popping operands or parameters off the stack, are they popped right to left or left to right? Why? (6) If we were to allocate the parameter variables to registers instead of storing them on the stack, what registers could we use? How would the use of those registers affect the code necessary for the haste() function? ------------------------ Other PA5 details - operands to < will be of same type, either byte and byte or integer and integer - Force all booleans to be 1 or 0, otherwise some of the implementation is overly complicated. For example, EqualityOp. - Button values will not be passed to user-defined functions. ------------------------ mstrout@cs.colostate.edu, 3/29/11 /** * PA5funcexample.java * * MMS, 3/28/11 */ import meggy.Meggy; class PA5funcexample { public static void main(String[] whatever){ new FuncEx().haste((byte)1,2,(byte)3,(byte)4, (byte)5,6,(byte)7,(byte)8); } } class FuncEx { public int haste(byte p1, int p2, byte p3, byte p4, byte p5, int p6, byte p7, byte p8) { if ((byte)0