Assignment 4, due June 26

Part of the homework for 22C:50, Summer 2003
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

 

Homework 4

  1. Look at the material on exception handling in
    	http://homepage.cs.uiowa.edu/~dwjones/syssoft/style.html
    
    This uses the C preprocessor macro mechanism. What is the output of the C preprocessor when it processes the following code fragments using the macros defined in exception.h?
            EXCEPT_CATCH( stack_overflow ) {
                    stack_push( a );
                    function_that_calls_push();
            } EXCEPT_HANDLER {
                    report_error();
            } EXCEPT_END;
    

    (Note: If you explore the man page for any Unix or Linux C or C++ compiler, you'll find that you can actually get the C preprocessor output with a bit of work. It's enough work that you're probably better off simply doing the macro expansion by hand, but if you have time, try both and use one to check your understanding of the other.)

  2. Here is an EAL macro that uses conditional assembly:
            MACRO ALIGN =x
              IF x > 1
                IF (x & 1) = 1
                  ERROR odd parameter to ALIGN
                ELSE
                  ALIGN (x>>)
                  .=.+(ABS(.)&(x>>1))
                ENDIF
              ENDIF
            ENDMAC
    

    Consider the following sequence of macro calls

    	ALIGN	1
    	ALIGN	2
    	ALIGN	3
    	ALIGN	4
    

    Part A: Hand expand these macros, showing the code that is actually assembled. (For this example, it is safe to assume that there is a macro preprocessor and you are supposed to show the output of that preprocessor).

    Part B: But what does it do? That is, if you had to write comments documenting an external, user's view of the ALIGN macro, what would you tell users it does.

  3. Here is a bit of EAL code:
    	A: W  5
    	X  =  .
    	.  =  #100
    	B: W  A
    	.  =  X
    	   W  B
    

    Part A: The above code defines the symbols A, B and X. Assuming a relocatable assembler, what are their values. Pay particular attention to the question of whether the value of each symbol is relocatable or absolute.

    Part B: Assume that this code has been assembled, and then you load the resulting object code with a relocation base of #FC. What memory locations get loaded, and what values are loaded in those locations?