Homework 11

22C:18, Fall 1996

Due Tuesday Dec. 3, 1996 in discussion

Douglas W. Jones
  1. In the notes for lecture 30 (Nov 15), some conditional assembly directives were used in some of the macros that were used. In SMAL, the conditional assembly directives are IF, ELSE, ELSEIF and ENDIF. Write a macro called TIMES that sets the assembly time symbol PRODUCT to the product of its two operands. Here's an assembly listing of an example run of a solution to this problem, minus the macro definition for times:
                        12          MACRO   PRINT =a
                        13            LIST +1
                        14            ; a
                        15            LIST -1
                        16          ENDMAC
                        17
                        18          TIMES   6,4
                        19          PRINT   PRODUCT
                        19            ; 24
                        20          TIMES   PRODUCT,2
                        21          PRINT   PRODUCT
                        21            ; 48
                        22          END
    
    Notice that the macros don't generate any code! TIMES only sets the value of the assembly-time symbol PRODUCT, and PRINT generates a comment containing the value of PRODUCT!

  2. Fix the instruction trap handler from Lecture 32 (Wednesday, Nov. 20) so that it sets the user's condition codes to reflect whether the results of the multiply instruction were negative or zero. (because the multiply procedure we're using doesn't detecto overflow, always leave the O and C condition codes set to zero).

  3. Consider the problem of writing an instruction trap handler that decodes and executes many tens of instructions that are implemented by software. The approach used in the example trap handler from Lecture 32 is not particularly good for this, since it requires masking and comparison with each candidate instruction that might need emulation. Propose a better way to decode the trapped instruction to determine whether it is a truly illegal opcode or one that requires a software implementation.

  4. Consider a memory management unit designed to prevent the user from jumping to random code within the operating system and designed to prevent the user from changing any data within the system. If the user program does anything like this, the result is a bus trap with the TMA register set to the address that was accessed (with a load, store or jump) and with the TPC register set to the address of the instruction that has not yet been executed. In the case of a jump to an illegal location, TMA = TPC; in the case of a load or store to an illegal location, TPC points to the load or store, and TMA points to the illegal operand in memory.

    Write a bus trap handler for this environment that allows a user to call a monitor procedur (for this example, allow calls to TIMES and don't worry about the others) while treating all other memory references as errors. The call to TIMES will have to be made by the trap handler!