CSCI 2321 (Computer Design), Spring 2020:
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.

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) Translate the following line of C into MIPS assembler:

    	B[6] = A[i] + B[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) Translate the following lines of C into MIPS assembler:

    	for (i = 0; i < a; i++)
    	    for (j = 0; j < b; j++)
    	        D[4*i + j] = i + j;
    

    assuming that

  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. (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
    

Honor Code Statement

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).1Text in italics is explanatory or something for you to fill in. For programming assignments, this should go in the body of the e-mail or in a plain-text file honor-code.txt (no word-processor files please).

Essay

Include a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what about the assignment you found interesting, difficult, or otherwise noteworthy. For programming assignments, it should go in the body of the e-mail or in a plain-text file essay.txt (no word-processor files please).



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.



2020-02-21