Midterm I

22C:50 Section 2, Fall 2000

Douglas W. Jones

Name: ________________________________________________

ID Number: ___________________

Please write your answers in the space provided! Make sure your name is in the same form as it appears on your University ID card! Illegible and excessively long answers will be penalized! This exam is open-book, open-notes, closed neighbor! This exam is worth 1/5 of the final grade (10 points; allocate 4 minutes per point).

  1. Hand assemble the following EAL code, and show what goes in the symbol table. For those lines of code that cause data to be stored in memory, show the memory address that is changed and the value stored in memory. There are many extra blanks! Do not fill in anything unused symbol table entries or next to lines that assemble nothing into memory. (2 points)
     line     hexadecimal     source
    number  location  value    text
    
      1    ________ ________       B    22           symbol table
                                                    symbol    value
      2    ________ ________  X:   B    #22
                                                  ________  ________
      3    ________ ________       B    X
                                                  ________  ________
      4    ________ ________  ; Commentary
                                                  ________  ________
      5    ________ ________       B    Y
                                                  ________  ________
      6    ________ ________       B    Z
    
      7    ________ ________  Y    =    10
     
      8    ________ ________  Z:
    
    For a bit more credit, circle the line numbers of the lines that cannot be properly processed on the first pass of a two pass assembler. (0.5 points)

  2. Consider this bit of C (or equally, C++) code:
    #define twice(x) x * 2
    #define next(x) x + 1
    int i = twice(next(4));
    
    (1.2 points)

    a) What is the actual parameter to next? __________

    b) What is the actual parameter to twice? __________

    c) What does twice(next(4)) get replaced with? _______________

    c) What is the initial value of i ? __________

  3. Hand assemble the following EAL code, and show what goes in the symbol table. For those lines of code that cause data to be stored in memory, show the memory address that is changed and the value stored in memory. There are many extra blanks! Do not fill in anything unused symbol table entries or next to lines that assemble nothing into memory. (2 points)
     line     hexadecimal     source
    number  location  value    text
    
      1    ________ ________       B    X
    
      2    ________ ________  Z:                     symbol table
                                                   symbol    value   abs/rel
      3    ________ ________  .    =    .+1
                                                  ________  ________  ____
      4    ________ ________  X:   B    15
                                                  ________  ________  ____
      5    ________ ________  Y:   B    15
                                                  ________  ________  ____
      6    ________ ________  .    =    Z
                                                  ________  ________  ____
      7    ________ ________       B    Y
     
      8    ________ ________  .    =    Y+1
    
    For a bit more credit, for each symbol in the above symbol table, indicate whether it would be absolute or relocatable. (0.5 points)

  4. Consider the following fragment from the grammar for LISP:
    <s-expr> ::= <atom>
              |  ( [ <s-expr> { <s-expr> } [ . <s-expr> ] ] )
    
    Fill in the blanks in the following C code fragment to complete the skeleton for a parser for this fragment. (2 points)
    void parse_s_exper()
    {
        if (lex_this != '(') {
            
            _________________________________
        } else {
            lex_scan();
            if (                                 ) {
                _________________________________
                parse_s_expr();
                while ((                                 )
                        _________________________________
                &&     (lex_this != ')')) {
                                                         ;
                        _________________________________
                }
                if (lex_this == '.') {
                                                     ;
                    _________________________________
                    parse_s_expr();
                }
            }
            if (lex_this != ')') EXCEPT_RAISE( parse_error );
            lex_scan();
        }
    }
    
  5. Hand assemble the following bit of EAL code, showing what goes in memory. (1.8 points)
            MACRO X I             0000: _________
              IF I > 0
                B I               0001: _________
                X (I-1)
              ENDIF               0002: _________
            ENDMAC
                                  0003: _________
            X 0
            X 1                   0004: _________
            X 2
            X 3                   0005: _________