Thông tin tài liệu
University of Washington Section 5: Procedures & Stacks Stacks in memory and stack operations The stack used to keep track of procedure calls Return addresses and return values Stack-based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture Stack-Based Languages University of Washington Stack-Based Languages Languages that support recursion e.g., C, Pascal, Java Code must be re-entrant Multiple simultaneous instantiations of single procedure Need some place to store state of each instantiation Arguments Local variables Return pointer Stack discipline State for a given procedure needed for a limited time Starting from when it is called to when it returns Callee always returns before caller does Stack allocated in frames State for a single procedure instantiation Stack-Based Languages University of Washington Call Chain Example yoo(…) { • • who(); • • } Example Call Chain yoo who(…) { • • • amI(); • • • amI(); • • • } who amI(…) { • • amI(); • • } Procedure amI is recursive (calls itself) Stack-Based Languages amI amI amI amI University of Washington Stack Frames Previous Frame Contents Local variables Function arguments Return information Temporary space Frame Pointer: %ebp Frame for current proc Stack Pointer: %esp Management Space allocated when procedure is entered “Set-up” code Space deallocated upon return “Finish” code Stack-Based Languages Stack “Top” University of Washington Stack Example yoo(…) { • • who(); • • } yoo %ebp yoo who amI %esp amI amI amI Stack-Based Languages University of Washington Stack Example who(…) { • • • amI(); • • • amI(); • • • } yoo yoo who %ebp amI amI who %esp amI amI Stack-Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who %ebp amI amI %esp amI Stack-Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who amI amI amI %ebp amI %esp Stack-Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who amI amI amI amI %ebp amI %esp Stack-Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who amI amI amI %ebp amI %esp Stack-Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who %ebp amI amI %esp amI Stack-Based Languages University of Washington Stack Example who(…) { • • • amI(); • • • amI(); • • • } yoo yoo who %ebp amI amI who %esp amI amI Stack-Based Languages University of Washington Stack Example amI(…) { • • • • • } yoo yoo who amI amI who %ebp amI amI %esp amI Stack-Based Languages University of Washington Stack Example who(…) { • • • amI(); • • • amI(); • • • } yoo yoo who %ebp amI amI who %esp amI amI Stack-Based Languages University of Washington Stack Example yoo(…) { • • who(); • • } yoo %ebp yoo who amI %esp amI amI amI Stack-Based Languages ... amI amI Stack- Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who %ebp amI amI %esp amI Stack- Based Languages University of Washington Stack. .. %esp Stack- Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who amI amI amI amI %ebp amI %esp Stack- Based Languages University of Washington Stack. .. %esp Stack- Based Languages University of Washington Stack Example amI(…) { • • amI(); • • } yoo yoo who amI amI who %ebp amI amI %esp amI Stack- Based Languages University of Washington Stack
Ngày đăng: 09/11/2019, 07:11
Xem thêm: 03 stack based languages 09 14 tủ tài liệu bách khoa