Assignment 4, due Feb 10

Part of the homework for 22C:60 (CS:2630), Spring 2012
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. Background: Consider the following SMAL Hawk assembly language program:
            INT     MAIN
            S       MAIN
    MAIN:   H       #01D1
            H       #02D2
            H       #1233
            H       #F4E4
            H       #FFFF
            H       #64F4
            H       #0010
            H       #FF00
            END
    

    This program consists entirely of Hawk machine instructions, but they have been coded in hex instead of using the full range of tools provided by the SMAL assembler. All but one of these instructions are documented in Chapter 4 of the notes (one is from Chapter 5). Appendix B of the Hawk manual lists the binary code for all of the instructions. If you run this program, note that the Hawk emulator includes a disassembler.

    a) Translate the H directives in the above program into symbolic assembly language. That is, replace, for example, H #F3F2 with MOVE R2,R3. What you are doing for this assignment is called disassembling the since you are undoing what the assembler normally does for you. (1.0 points)

    b) What does the program do? That is, what values does it leave in what registers when it executes? (0.5 points)

  2. Background: Consider this broken fragment of assembly code.
            LIS     R3,4000
            ADDSI   R3,12
            ADDI    R3,1000000
    

    If you assemble it, you will get several error messages. Note, however, that the intent of this code is clear, it is trying to load 4000 (decimal) into R3, then increment that register by twelve and then increment it by a million.

    a) Give the sequence of halfwords that the assembler should place in memory to represent the above instructions, using hexadecimal, with question marks substituted for the hex digits that correspond to the erroneous parts. (0.5 points)

    b) Replace each of the instructions above with an appropriate instruction (or instruction sequence) that does the intended operation, eliminating the error. If you need an extra register, use R4. (1.0 points)

Machine Problem 2

Due Feb. 20

The Fibonacci series is a famous sequence of numbers that begins
    0 1 1 2 3 5 8 13
Each element of this series is the sum of its two predecessors. In a typical high level computer language, this sequence could be computed using a program something like this:

     I = 0
     J = 1
     repeat
         output I followed by one space
         K = I + J
         I = J
         J = K
     forever

Your assignment is to write a Hawk main program that computes and prints the first 24 elements of this series using the above algorithm. You should use subroutines from the Hawk monitor to print the successive numbers in the series and the spaces between them. All of the Hawk instructions and Hawk monitor subroutines needed to solve this problem are documented in Chapter 5 of the notes.

Submission Instructions

Your source file must be named mp2.a all lower case. This file must exist on the departmental linux cluster. Use the division of math-sciences coursework submission tools to submit this file. For instructions, see:

-- http://www.divms.uiowa.edu/help/msstart/submit.html

Grading

The grader will assemble and run your code, and will comment, on your assembly listing, about any deficiencies in your work.

The algorithm you are to use is fixed, but how you embed this algorithm in your main program can vary considerably. You are responsible for selecting the registers used to hold variables, and you are responsible for making your code readable, including use of white space and comments.

You will be penalized for any of the following errors:

A suggestion: Work incrementally. First, get your program to output 24 zeros. This will test if you have a working for loop. Then get it to output a sequence of ascending integers, so you can start playing with arithmetic. Then, finally, get it to do Fibonacci numbers. Don't waste time on broken code, throw it away and start over. Always keep backup copies of each small success, so you minimize your losses when you throw away code. Start with a working Hello World program, so you always have something to fall back on. Discard backups only after they become irrelevant.