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

Credit:
30 points.

Reading

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

Problems

Answer the following questions. You may write out your answers by hand and scan them, or you may use a word processor or other program, but please submit a PDF or plain text via e-mail to my TMail address. (No links to shared files on Google Drive please.) Please use a subject line that mentions the course and the assignment (e.g., “csci 2321 hw 2” or “computer design hw 2”).

Tips:

  1. (5 points) Translate the following line of C into MIPS assembler:

    	B[6] = A[i] + A[j];
    

    assuming that

  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) Given a machine-language instruction 0x02108020 (0x denotes a base-16 value), what is the corresponding MIPS assembler-language instruction?

  4. (5 points) Given the following initial contents for registers $t1 and $t2:

    $t1 0xFFFFFFFF
    $t2 0x12345678

    For each of the following sequences of MIPS instructions, if $t1 and $t2 are as above, what does $t0 contain, in hexadecimal, after it is executed?

  5. (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. (You can use int to represent a 32-bit integer; that's what a “word” is in MIPS. So MemArray is an array of 100 ints.)


            .text
            addi    $t1, $0, 0
            la      $s0, MemArray
            addi    $s2, $0, 0
    LOOP:   lw      $s1, 0($s0)
            add     $s2, $s2, $s1
            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
    

Pledge

For programming assignments, this section should go in the body of the e-mail or in a plain-text file pledge.txt (no word-processor files please). For written assignments, please put it in the text or PDF file with your answers.

Include the Honor Code pledge or just the word “pledged”, plus at least one of the following about collaboration and help (as many as apply). Text in italics is explanatory or something for you to fill in.

Essay

For programming assignments, this section should go in the body of the e-mail or in a plain-text file pledge.txt (no word-processor files please). For written assignments, please put it in the text or PDF file with your answers.

Include a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what if anything you think you learned from the assignment, and what if anything you found interesting, difficult, or otherwise noteworthy.




2021-03-05