Assignment 6, due Feb 28

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

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. A collection of small problems related to addressing modes:

    a) Assume that the identifier A has been defined as some ASCII character. Write SMAL Hawk assembly code to load A into R3. (0.2 points)

    b) Assume that the identifier B is the memory address of a global variable. Write SMAL Hawk assembly code to load the value of the variable at B into R3. (0.2 points)

    c) Assume that the identifier C is the displacement of a local variable from the start of the activation record. Write SMAL Hawk assembly code to load the value of the variable at C into R3. (0.2 points)

    d) Assume that R3 holds the address of a variable in memory. Write SMAL Hawk assembly code to load the value of that variable into R4. (0.2 points)

    e) Assume that the identifier E is the displacement of a field of a record pointed to by R3 Write SMAL Hawk assembly code to load the value of the record field E into R4. (0.2 points)

  2. Background: Here is the source code for the program mp1test.a that was used to test MP1. A few lines have been deleted, but all the comments are still there.
            TITLE   "mp1test.a test program for MP1"
    
            USE     "hawk.h"
            USE     "monitor.h"
    
            INT     MAIN
            S       MAIN
    
    ; traverse a list of records starting with HEAD
            EXT     HEAD
    
    ; each record contains the following fields:
    NEXT    =       0       ; 32-bit pointer to the next record, or NULL
    X       =       4       ; 32-bit X coordinate
    Y       =       8       ; 32-bit Y coordinate
    TEXT    =       12      ; 32-bit pointer to the text to output at X and Y
    
    ; the main program activation record
    ARSIZE  =       4
    ;RETAD  =       0
    
    ; the main program
    MAIN:   STORES  R1,R2
            ADDI    R2,R2,ARSIZE
    
            LIL     R8,HEAD         ; p = head
    LOOP:
            TESTR   R8
            BZS     QUIT            ; while (p != NULL) do {
    
            _________________       ;   -- parameter p->x    (a)
            _________________       ;   -- parameter p->y    (b)
            LIL     R1,PUTAT
            JSRS    R1,R1           ;   putat( p->x, p->y )
    
            _________________       ;   -- parameter p->text (c)
            LIL     R1,PUTS
            JSRS    R1,R1           ;   puts( p->text )
    
            _________________       ;   p = p->next          (d)
    
            BR      LOOP            ; }
    QUIT:
            ADDI    R2,R2,-ARSIZE
            LOADS   R1,R2
            JUMPS   R1              ; return to the monitor to stop
    

    A Problem Give the correct code for the comments for the the lines with the blanks and the right marginal (a) (b) (c) and (d). (0.2 points each)

    Note: Please do not turn in the whole program. Just indicate the correct line of code for each part.

    Aside: You can test your code by assembling it and linking the object of your assembly with your solution to MP1 in order to demonstrate that it does exactly the same thing as the official MP1 test program.

  3. Background: Consider this definition of a mathematical function f defined over non-negative integers:

    if a = 0: f(a,b) = 0

    if a ≠ 0: f(a,b) = f(b,a – 1) + b

    For example: f(1,2) = f(2,0) + 2 = (f(0,1) + 0) + 2 = (0 + 0) + 2 = 2

    a) Write SMAL code for a recursive Hawk subroutine to compute f. The subroutine should be called (creatively) F, and of course, you should write clear and easy to read code. (1.0 points)

    b) The function f discussed here is very common. You spent considerable time studying it in elementary school. What is the proper name for f. (0.2 points)