Homework 1

22C:116, Fall 1999

Due Friday Aug 27, 1999, in class

Douglas W. Jones

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!

This assignment is dominated by review questions that are not as much specific to the material in the book as they are to material you should have learned in prior courses or work experience.

  1. What is your E-mail address? (If you have more than one, give the address you'd prefer used for class purposes.)

  2. Background: Read the UNIX man pages for setjmp() and longjmp(). Note that the intended purpose of these routines is for exception handling. A program will typically use setjmp to remember the context of the outer loop of the program, and whenever a computation in an inner part of the program, perhaps in a function called by a function called by a function detects an error that requires an escape to the outer loop, it uses longjmp() to get there.

    FORTRAN, an ancient computer language, contained a somewhat similar feature, the assigned GOTO. A program could assign a label to a variable and then later, use that variable as the target of a GOTO statement. The implementation of an assigned GOTO was trivial. The assign statement simply loaded the address referenced by the label into the variable, and the assigned GOTO simply did an indirect jump through the indicated variable.

    The Problem: What is the difference between a control transfer initiated by longjmp() and a control transfer initiated by the older FORTRAN assigned GOTO.

  3. Background: The PIC microcontroller (a very small microcomputer made by Microchip Inc) has an asynchronous serial output port which is controlled by the application program through the following 4 registers (ignoring details related to baud rate selection and synchronous transmission):
             _______________________________________
    PIE1	|    |    |    |TXIE|    |    |    |    |
        	|____|____|____|____|____|____|____|____|
    	TXIE = 0 -- transmit interrupt disabled
    	TXIE = 1 -- transmit interrupt enbaled
    			an interrupt will be requested
    			if TXIF=1 and TXIE=1
    
             _______________________________________
    PIR1	|    |    |    |TXIF|    |    |    |    |
        	|____|____|____|____|____|____|____|____|
    	TXIF = 0 -- transmit data register is in use
    	TXIF = 1 -- transmit data register available
    		
             _______________________________________
    TXREG   |        Transmit Data Register         |
        	|_______________________________________|
    	assignment of one character to TXREG when TXIF=1
    	will set TXIF=0 until the character in TXREG has
    	been enqueued by the hardware for transmission.
    
             _______________________________________
    TXSTA   |    |TX9 |TXEN|    |    |    |TRMT|TX9D|
        	|____|____|____|____|____|____|____|____|
    	TX9  = 0 -- Transmit 8 bit data
    	TX9  = 1 -- Transmit 9 bit data
    	TXEN = 0 -- Disable transmitter
    	TXEN = 1 -- Enable transmitter
    	TRMT = 0 -- The transmitter queue is empty
    	TRMT = 1 -- There is data in the transmitter queue
    	TX9D     -- the 9th bit of TXREG if TX9=1.
    			note, assign to TX9D first before
    			assigning to TXREG for 9 bit data!
    

    Part A: How would you initialize these registers, and which of these registers would you initialize, prior to using this interface.

    Part B: Write high level pseudocode for a function, TXPUTC, that outputs one character to the asynchronous serial port. This function should use polling to await the port-ready condition, then output the 8-bit character with mark parity. Assume the register names can be safely used as variable names in your code!