NCNU System Programming Final Exam

Date: January 19th, 2007
Time: 09:10-
  1. (10%) Consider the assembly code with macro invocations in the following program.  After the macros are expanded, can we use a 1-pass assembler to handle this program?  Why?
    XMAS
    START 
     1000
    PRINT
    MACRO
     &CH
    $LOOP
    TD
     OUTDEV

    JEQ
     $LOOP

    LDCH
    #&CH

    WD
     OUTDEV

    MEND

    OUTDEV 
    BYTE
     x'06'
    HEIGHT
    WORD
     4
    MARGIN
    WORD
     5
    I
    RESW
     1
    J
    RESW
     1
    EXPR1
    RESW
     1
    FIRST
    LDA
    #1
    L1B
    STA
     I

    COMP
     HEIGHT

    JGT
     L1E

    LDA
     I

    ADD
    #2

    STA
     EXPR1

    LDA
     I
    L2B
    STA
     J

    COMP
     EXPR1

    JGT
     L2E

    LDA
     MARGIN

    ADD
    #1

    SUB
     J

    RMO
     A,S

    LDX
    #1
    L3B
    COMPR
     X,S

    JGT
     L3E

    PRINT
     32

    TIXR
     X

    J
     L3B
    L3E
    LDA
     J

    MUL
    #2

    SUB
    #1

    RMO
     A,S

    LDX
    #1
    L4B
    COMPR
     X,S

    JGT
     L4E

    PRINT
     42

    TIXR
     X

    J
     L4B
    L4E
    PRINT
     00

    LDA
     J

    ADD
    #1

    J
     L2B
    L2E
    LDA
     I

    ADD
    #1

    J
     L1B
    L1E
    LDA
    #1
    L5B
    STA
     I

    COMP
     HEIGHT

    JGT
     L5E

    LDA
     MARGIN

    SUB
    #1

    RMO
     A,S

    LDX
    #1
    L6B
    COMPR
     X,S

    JGT
     L6E

    PRINT
     32

    TIXR
     X

    J
     L6B
    L6E
    LDX
    #1

    LDS
    #3
    L7B
    COMPR
     X,S

    JGT
     L7E

    PRINT
     42

    TIXR
     X

    J
     L7B
    L7E
    PRINT
     00

    LDA
     I

    ADD
    #1

    J
     L5B
    L5E
    RSUB


    END
     FIRST

  2. (10%) If we use a two-pass assembler to assemble it to an object file, what is the value of the program size in the Header record?
  3. (10%) Show the output (at device 06) that we shall obtain when we run the above SIC/XE assembly program.

  4. (10%) Translate (by hand) the following assembly program to SIC/XE object code.
    REF
    START
     1000
    . Subroutine EXCH
    EXCH
    LDA
    @P1

    STA
     TEMP

    LDA
    @P2

    STA
    @P1

    LDA
     TEMP

    STA
    @P2

    RSUB

    P1
    RESW
     1
    P2
    RESW
     1
    TEMP
    RESW
     1
    . Main program
    MAIN
    LDA
    #1

    STA
     I

    LDA
    #3

    STA
     J
    . Call a subroutine

    LDA
    #I

    STA
     P1

    LDA
    #J

    STA
     P2

    JSUB
     EXCH
    I
    RESW
     1
    J
    RESW
     1

    END
     MAIN

  5. (10%) By specifying the memory addresses, explain how the "indirect addressing" is utilized in the above subroutine to modify the values of variables in the main program.
  6. (10%) Suppose we made the following changes to the program in Figure 2.9:
  7. Show the resulting object code for lines 45, 135, 145, 215, and 230. Also show the literal pool with addresses and data values. Note: you do not need to re-translate the entire program to do this.

  8. (10%) In the program of Figure 2.11, suppose we used only two program blocks: the default block and CBLKS. Assume that the data items in CDATA are to be included in the default block.  What changes in the source program would accomplish this?  Show the length and address of these program blocks as shown in Page 80.
  9. (10%) Consider an extended version of SIC/XE that has a new register R.  The contents of R cannot be accessed or changed by the user program.  When a program is loaded, however, the loader sets register R so that it contains the starting address of the program.  For simplicity, assume that this version of SIC has no program-counter or base relative addressing - thus, all instructions that refer to memory must use Format 4.
    Each time the program refers to an address in memory, the contents of register R are automatically added into the target address calculation.  Suppose, for example, that an assembled instruction specifies an address of 800 (hexadecimal).  If R contains 5000, executing this instruction would actually refer to memory address 5800.  If R contains 8000, executing the same instruction would actually refer to memory address 8800.
    Consider the control sections shown in Figure 3.8.  Assume that these control sections are being loaded and linked at the addresses shown in Figure 3.10; thus the loader will set register R to the value 4000. 
    1. What value should appear in the External Symbol Table of the loader for the symbol LISTB?
    2. What should the instruction labeled REF2 in the control section PROGC look like after all loading and linking operations have been performed?

  10. (10%) Suppose we have the macro definition of ABSDIFF as
    #define   ABSDIFF(X,Y)     X > Y ? X - Y : Y - X
    #define   DISPLAY(EXPR)   printf(#EXPR "= %d\n", EXPR)
    1. Expand the macro invocation
      DISPLAY( ABSDIFF(3-1, 9+3) );
    2. If we execute the C program containing this statement, what output will be produced?
  11. (10%) Refer to the definition of RDBUFF that appears in Figure 4.8(a).  Each of the following macro invocation statements contains an error.  Which of these errors would be detected by the macro processor, and which would be detected by the assembler?
    1. RDBUFF  F3, BUF, RECL, ZZ
    2. RDBUFF  F3, BUF, RECL, 04, 2048, 01
      • { too many arguments }
    3. RDBUFF  F3, ,RECL, 04
      • { no value specified for &BUFADR }
    4. RDBUFF  F3, RECL, BUF
      • { arguments specified in wrong order }