Day10 - o Don’t know if callee might alter, so save this...

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

View Full Document Right Arrow Icon
Call/Return Protocols 10/4/11 Observe: register set used for efficient access to temp/intermediate data Issue o Registers are global, software development is local o Vaule in %ecx is set by foo, not main, but developer of main might not know this One bad situation o Every subroutine documents its register usage o Let’s count the ways this is bad! # subroutines X # calls to subroutines = # of ways to goof Aspect of a good situation o Like to maintain register state in calling routine so registers can be effectively used Need to save registers if they are to be used in callee Routine and caller routine In earlier caller is main, callee is foo The stack is traditionally used for this purpose but who is responsible for saving? One Approach o Caller save registers Value in %ecx is set in main, not in foo o Pushl – puts on the stack o Pop – takes off the stack Caller save protocol o Only save what needs to be kept unaltered ++
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: o Don’t know if callee might alter, so save this that might • 2 nd approach: callee save registers o Only save what is altered ++ o Don’t know if save value is live – • Actual x86 conventioon o Mixture of callee and caller save: Caller save %eax, ecx, and edx Callee save ebx, esi, and edi o Perform save only when needed, based on local information • Eg. Move eax usage to ebx o Caller, callee save status is now one of the many considerations for what registers to use • Stack o How does it really work? • Other uses for stack o Passig parameters to subroutines o Local variables within subroutines Motivates stack frame, region of stack associated with a particular invocation of a function/subroutine o Top of stack always available via %esp o Stable reference relative to call %ebp (Called Frame Pointer)...
View Full Document

This note was uploaded on 12/05/2011 for the course ENGINEERIN 131 taught by Professor Cytron during the Spring '11 term at Washington University in St. Louis.

Ask a homework question - tutors are online