11/11/2006


A student writes:

Dr. Patt,
I have a question on problem 5 on problem set 5.  While writing the
subroutine  for both parts would it be good practice to Save the current
contents of the various registrars used within the subroutine to get the
process done or should we just assume that all other registrers will be
clear to be used?  Only one question as of right now in between cutting
down a couple trees for my mom.  hope you are having a good weekend.

<<name withheld to protect the local logger>>


The thing to keep in mind (first of all) is this:

          Who knows which register(s) will be clobbered?  

Certainly the CallER knows that JSR will clobber R7.  So, if the CallER 
has a value in R7 that is needed AFTER returning from the subroutine, 
the CallER had better put a ST R7, SaveR7 just before the JSR instruction.  
If the value in R7 (prior to the JSR) is not needed after the subroutine 
is executed, the CallER need not save it.

AND, usually only the CallEE knows which registers are needed to perform
the job of the subroutine, so the CallEE saves the registers it needs to
do the job, and then restores them after the job of the subroutine is done.

Of course, one could save all the registers and be safe.  But that is
unnecessary and time consuming.  ...and we do care how long it takes
for a program to execute.

Okay? 
Yale Patt