Homework 5

22C:18, Summer 1997

Due Monday, July 14

Douglas W. Jones
The following questions should all be answered in the context of the new file
	/group/class/22c018/highlevel.h
This header file can be used instead of the old hawk.system file in order to simplify writing programs that reference external procedures. It contains one macro called, poetically enough "CALL" that will call any procedure, whether it's locally defined or external. The macros EXTERNAL and GLOBAL take care of many of the details of global linkage, while the macros GET and PUT handle the load and store on local or global variables. Programmers need merely define their variables using the macros LOCAL and GLOBAL, and everything else is automated!

Your job for this assignment is to understand these macros and, in answering the following questions, prove that you understand them.

  1. The new MAINBEGIN macro and the new CALL macro use a different calling sequence to reference externally linked procedures and functions. Explain how and why this works. That is, given that PROC is an external procedure, why is
    	JSR	R1,PROC
    
    illegal while the following is legal:
    	LIS	R1,0
    	JSR	R1,R1,PROC
    
  2. Analyze the expected storage requirements and running speed of the two external calling sequences you have seen:
            LIS     R1,0
            JSR     R1,R1,PROC
    
    and
            LOAD    R1,PPROC
            JSRS    R1,R1
    
    And answer the following question: If your program was bigger than 64K, would the new calling sequence still be useful?

  3. Propose an improved version of the PROCBEGIN that is illegal inside a procedure or inside the body of the main program. Use the tricks shown in the LOCAL and GLOBAL macros to figure out where PROCBEGIN is legal and where not.

  4. As an extension to the above question, consider combining PROCEND and MAINEND into one macro that would first report an error if not called in the context of PROCBEGIN or MAINBEGIN and second, generate the appropriate sequence of instructions depending on the context, so END in the context of a PROCBEGIN would be the same as PROCEND, while END in the context of a MAINBEGIN would be the same as a MAINEND.

  5. Rewrite your solution to problem problem 1 of Homework 4 to make effective use of these new macros. You won't necessarily need all of them, but you can in fact use most of them, and in doing so, you can make your program noticably more readable!