Friday, November 13, 2009 4:16 PM,



A student writes:



	 Hello Professor Patt,
	 I just had a quick question about pg 268 in the book. This is not 
	 terribly important so if you do not have time to address it feel free 
	 to move on. When writing the code for the OpAdd subroutine for the 
	 calculator don't you have to save the value of R7 before the program 
	 because the JSR instructions inside the program will clobber what is 
	 in r7 for their use right? Then before calling the return at the end 
	 the Opadd subroutine you would just restore
	 r7 to the proper value so it can return to the calling calculator 
	 program right?
	 Thanks
	 <<name withheld to protect the student who caught me being sloppy>>



You absolutely do!  Thank you for pointing it out.

As it turns out, in the actual calculator code later in Chapter 10, you notice 
that we did not actually JSR to the OpAdd routine, so the code you are 
referring to will work in that example.  However, since on page 268, we showed 
it as subroutine (it ends with RET on line 14), RET will not work properly if 
we don't do as you say, save R7 at the front and restore it just before the 
RET.

Again, thank you for pointing it out.
 
Yale Patt