Assignment 4, due June 26
Part of
the homework for 22C:50, Summer 2003
|
EXCEPT_CATCH( stack_overflow ) { stack_push( a ); function_that_calls_push(); } EXCEPT_HANDLER { report_error(); } EXCEPT_END;
Here is the result of expanding the macros, but with the indenting fixed -- if you just expand them without fixing the indenting, it's less obvious what is going on. (I admit, it's not easy to call anything about this code obvious, but the random indenting that you get from the C preprocessor is even worse!)
{ struct exception_ * except_save = stack_overflow; struct exception_ * *except_who = &stack_overflow; struct exception_ except_new; if (setjmp( except_new.jb ) == 0) { stack_overflow = &except_new; { stack_push( a ); function_that_calls_push(); } *except_who = except_save; } else { *except_who = except_save; { report_error(); } } }
MACRO ALIGN =x IF x > 1 IF (x & 1) = 1 ERROR odd parameter to ALIGN ELSE ALIGN (x>>1) .=.+(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).
; ALIGN 1 becomes nothing ; ALIGN 2 becomes .=.+(ABS(.)&(2>>1)) ; ALIGN 3 becomes ERROR odd parameter to ALIGN ; ALIGN 4 becomes .=.+(ABS(.)&((4>>1)>>1)) .=.+(ABS(.)&(4>>1))
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.
If n is not a power of 2, ALIGN n will lead to an error (if we assume ERROR is an undefined opcode.)
If n is a power of 2 greater than 1, the behavior of ALIGN n is more complex. We need to make an assumption about the meaning of ABS. It makes sense to assume that it takes the absolute value, but since the location counter is best interpreted as an unsigned integer, perhaps it really means the absolute component of a value that might be relocatable.
So, for n a power of 2 greater than 1, ALIGN n guarantees that the ABS of location counter will be a multiple of n. It does this recursively, first guaranteeing that it is a multiple of n/2 n>>1, and then adding n/2 if needed in order to finish the job. Thus, ALIGN 8 will add some subset of 1, 2 and 4 to the location counter, in that order, to force the location counter to be a multiple of 8.
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.
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?
EAL V3.0 by Douglas W. Jones; Mon Jul 7 14:26:25 2003 1 0000+ 0005: |A: W 5 2 |X = . 3 |. = #100 4 0100: 0000+ |B: W A 5 |. = X 6 0002+ 0100: | W B ; symbol table: A = #0000+ B = #0100 X = #0002+