CSCI 2321 (Computer Design), Spring 2017:
Homework 2

Credit:
40 points.

Reading

Be sure you have read, or at least skimmed, the assigned readings from Chapter 2 up through 2.7.

Honor Code Statement

Please include with each part of the assignment the Honor Code pledge or just the word ``pledged'', plus one or more of the following about collaboration and help (as many as apply).1Text in italics is explanatory or something for you to fill in. For written assignments, it should go right after your name and the assignment number; for programming assignments, it should go in comments at the start of your program(s).

Problems

Answer the following questions. You may write out your answers by hand or using a word processor or other program, but please submit hard copy, either in class or in one of my mailboxes (outside my office or in the ASO).

Tips:

  1. (5 points) Do problem 2.9 from the textbook.

  2. (5 points) For each of the following MIPS instructions, translate it into machine language, first listing all the fields (e.g., opcode) in binary and then giving the 32-bit instruction in hexadecimal.

  3. (5 points) Do problem 2.14 from the textbook.

  4. (5 points) If registers $t1 and $t2 initially contain the following:

    $t1 0xFFFFFFFF
    $t2 0x12345678

    For each of the sequences of MIPS instructions, what does $t0 contain, in hexadecimal, after it is executed?

  5. (10 points) Do problem 2.27 from the textbook.

  6. (10 points) Reverse-compile the following MIPS assembly code into equivalent C (without use of go to), using integer variable i to represent the value in $t1 and integer variable result to represent the value in $s2. (Assume that integer variables here are of whatever type matches MIPS's idea of a ``word'', i.e., four bytes. So MemArray is an array of 100 integers.)


            .text
            addi    $t1, $0, 0
            la      $s0, MemArray
            addi    $s2, $0, 0
    LOOP:   lw      $t2, 0($s0)
            add     $s2, $s2, $t2
            addi    $s0, $s0, 4
            addi    $t1, $t1, 1
            slti    $t2, $t1, 100
            bne     $t2, $0, LOOP
    
            .data
    MemArray: .space 400  # reserve space for 400 bytes, i.e., 100 words
    



Footnotes

... apply).1
Credit where credit is due: I based the wording of this list on a posting to a SIGCSE mailing list. SIGCSE is the ACM's Special Interest Group on CS Education.


Berna Massingill
2017-02-20