Assignment 3, Solutions

Part of the homework for 22C:60 (CS:2630), Spring 2013
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: Consider the following code, written in SMAL:
            B       239
            B       -66
            H       57005
    

    A Problem: If you assemble this and load it into memory, these two bytes plus a halfword can be viewed as a single word in memory. What is the value of that word in hexadecimal? (1.2 points)

    DEADBEEF
    

    This value was chosen because it is one the best known hexadecimal values that reads as an English phrase. Other popular alternatives include FEED and DEAF. If you allow zero and one to stand for similar looking letters, a few more words become possible.

    Suggestion: Do it by hand first, converting the three parts to binary and then shuffling them into the correct fields of a 32 bit word before converting the results to hex. Then check your work by assembling this code using the SMAL assembler and then loading the resulting object file into the Hawk emulator to see what actually loads in memory. If you do this, you prove that you understand what the assembler did and you check your work.

  2. Background: Here is a fragment of SMAL code that creates a null-terminated linked list data structure, where each element contains a pointer to the next element of the list and an integer. The head of the list has the label HEAD.
    NULL    =       0
    VALUE   =       1
    BIG     =       2
    
    HEAD:   W       CO,  VALUE+BIG
    AX:     W       DE,  VALUE
    BE:     W       NULL,(BE-HEAD)+1
    CO:     W       EE,  BIG >> VALUE
    DE:     W       BE,  (DE-CO)+1
    EE:     W       AX,  BIG+BIG
    

    a) What values does this place in memory? As above, you will learn more from this question if you do it by hand and then check your work using SMAL. (0.6 points)

    Here is the answer, in hex:

    000000: 00000018
    000004: 00000003
    000008: 00000020
    00000C: 00000001
    000010: 00000000
    000014: 00000011
    000018: 00000028
    00001C: 00000001
    000020: 00000010
    000024: 00000009
    000028: 00000008
    00002C: 00000004
    

    b) If you traverse this list, starting at the head and continuing until you reach a null pointer, what integer values are found in each list element (list them from left to right and you should almost recognize a pattern -- unfortunately, the problem statement above got scrambled, and the last two list elements break the intended pattern). (0.6 points)

    Here are the list elements, lifted from the above answer, and placed in order using the pointer fields of each list element:

    000000: 00000018
    000004: 00000003
    
    000018: 00000028
    00001C: 00000001
    
    000028: 00000008
    00002C: 00000004
    
    000008: 00000020
    00000C: 00000001
    
    000020: 00000010
    000024: 00000009
    
    000010: 00000000
    000014: 00000011
    

    Writing down the values from left to right in decimal, we get this:

    3 1 4 1 9 17
    

    It was supposed to be successive digits of Pi, but for the error in the problem statement.

    
    

  3. A Problem: The instructions for MP1 say to hit the r key twice in order to run your code. The instructions explain that the first time you hit the r key, it runs some kind of operating system code. What values are in registers 1 to 4 after the first time you hit r (these depend only on the little bit of operating sytem code). (0.6 points)

    Here is a screen-shot from the Hawk emulator showing the result:

     HAWK EMULATOR
       /------------------CPU------------------\   /----MEMORY----\
       PC:  00001000                R8: 00000000   000FFC: NOP
       PSW: 00000000  R1: 0000000E  R9: 00000000   000FFE: NOP
       NZVC: 0 0 0 0  R2: 0001003C  RA: 00000000 -*001000: STORES  R1,R2
                      R3: 00000050  RB: 00000000   001002: LEACC   R2,R2,#0004
                      R4: 00000009  RC: 00000000   001006: LEA     R8,#001034
                      R5: 00000000  RD: 00000000   00100A: MOVECC  R0,R8
                      R6: 00000000  RE: 00000000   00100C: BEQ     #00102C
                      R7: 00000000  RF: 00000000   00100E: LOAD    R3,R8,#0000
    
     **HALTED**  r(run) s(step) q(quit) ?(help)
    

    As it turns out, the contents of R1 and R2 are deterministic, while the contents of R3 and R4 depend on your window size. This caused the TA some difficulty in grading; those who lost credit for unexpected values of R3 and R4 may get it back by seeing the TA.