H09 Practice Soln

No locals or temporaries conserves stack space and

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: stack. • No locals or temporaries conserves stack space and removes instructions to adjust stack pointer. • The increment of local and subsequent multiply by 4 are combined into one l ea instruction instead of separate instructions. • The loop is entered the first time without evaluating the test as the compiler can see that it will always be true, avoids a branch, saves instructions. Problem 2: Runtime stack char *GetArgv0(int mainSize) { void *mainAddr = (void *)main; // get address of main's code void **ebp = (void **)&mainSize - 2; // orient to current stack frame do { } void *ra = *(ebp + 1); // if RA within main, preceding frame is one we want if (ra > mainAddr && ra < (char *)mainAddr + mainSize) { void **ebp_of_main = (void **)*ebp; // deref one last time char **argv = *(ebp_of_main + 3); // get to second param return argv[0]; } }...
View Full Document

This note was uploaded on 02/06/2014 for the course CS 106X taught by Professor Cain,g during the Winter '08 term at Stanford.

Ask a homework question - tutors are online