CS 2733 Computer Organization II
Questions and Answers, Fall 2004

  1. Question (Tue Sep 21 12:59:11 CDT 2004): I submitted Recitation 4 today @ noon (9/21) and it said it was received correctly for full credit and would email me a copy... I never got a copy of the email, so I resubmitted and the same thing happened.

    Answer: In your case there are two copies archived, received about 2 minutes apart. The archiving seems to be working fine, but sometimes the email does not work -- I don't know why. One student complained about a workstation clock that was 5 hours fast, so if this happens to you, let me know.


  2. Question (Wed Sep 22 08:53:17 CDT 2004): In the instructions for Recitation 5 that are given below the C code, you state that the code for the addUp method should just add up registers $s0 (A), $s1 (N) and $s2 (B); however, the C-code given directly above those instructions state that C gets the sum of A[i], B[i] and i, not A[i], B[i] and N.

    Answer: I'm not sure why you think that addUp should add the registers $s0, $s1, and $s2.

    addUp is supposed to add its three input parameters, which under MIPS convensions would be $a0, $a1, and $a2, NOT $s0, $s1, and $s2 as you say above.

    In preparation for the call to writeArray from within main, following MIPS parameter convensions, you must load $a0 with the starting address of A, and load $a1 with the value of n. The writeArray function would mess up $a0, so unless you save its value, the same loads into $a0 and $a1 are needed in preparation to call the computeArray function from within main.

    From within computerArray, there is a call to the addUp function. In preparation for this call, you must load the values of A[i], B[i], and i into registers $a0, $a1, and $a2. Of course, addUp just adds these and returns the sum in $v0.

    Finally, from within computeArray, there is another call to writeArray. Here you must load $a0 and $a1 with the starting address of C and the value of n. In this case, you must not use a la instruction to get the starting address of C, since C should be allocated on the stack.

    Wheh!


  3. Question (Sun Sep 26 14:09:49 CDT 2004): The C code given for Recitation 5 passes A[i], B[i], and i to the addUp method. You said, in your previous email to me, that I should be passing $a0, $a1 and $a2 to the addUp method, yet $a1 is the value of n, not i. Am I right in assuming that n and i will be different values at different points in the code? If so, then addUp would be adding A[i], B[i] and n instead of A[i], B[i], and i.

    Answer: The MIPS convention of passing the first four parameters in registers $a0, $a1, $a2, and $a3 is there so that different individuals can write MIPS functions separately and have them work with one another. It is an artificial convention. It makes no difference what use the registers had previously been put to. In the current case, you are supposed to mirror the given C code faithfully:

    Initially, the call from main of writeArray(A, n) means that the address of A is loaded into $a0 and the value of n is loaded into $a1. As the function computeArray starts executing, the value of n is still in $a1. This makes no difference. Just before you make the call addUp(A[i], B[i], i), the values of A[i}, B[i], and i must be loaded into $a0, $a1, and $a2. It makes no difference that previously $a1 held the value of n. The value of n will be overwritten. (Wheh!)

    If you are writing a short MIPS program by yourself, there might be little or no benefit to following MIPS parameter conventions. (I asked you to follow them here for practice.) For example, suppose you are passing a single parameter, call it n, to a function. Then you load n into $a0 and call the function. Suppose the function called prints a message, and calls another function with the same parameter. In this case you must use $a0 as part of the syscall, so you must save the value of n somewhere, and then load it into $a0 again before the next function call. If you didn't need to follow MIPS conventions, you could save some loads.


  4. Question (Mon Sep 27 22:23:08 CDT 2004): I was looking at my Recitation 4 and noticed that in the text file I sent you, I did not write my name or course number on the top. Can you tell who sends the recitations if we do not write our name on top of the text file.

    Answer: No problem. The submissions are stored by CS account name, and we have that nicely cross-referenced with your real name (finger in Unix, or Roster by Username). We won't even notice the absence of your name!


  5. Question (Thu Oct 14 08:31:05 CDT 2004): The part about Recitation 7 that's giving me trouble is part 1. I understand that each MIPS instruction must be converted to it's hex representation for "Assembled Code", but that's where I get lost. I was assuming that once you compute the hex instruction for the first MIPS instruction in the program that you would simply add it to the hex number of where the program starts: for example, in the sample program, the first instruction is addi $t1, $0, 4 and the hex of that would be 31200004. Add that to the starting point of the program, 00400020, and, well, I don't get 20090004, which is shown on the answer sheet. Can you give me a hint or correct my assumptions as to how to go about this?

    Answer: I don't know where you're getting 31200004. Start with addi $t1, $0, 4. The opcode is 8hex = 810. The code for $t1 is 9 and of course $0 is 0. Remember that in the machine language, the target register comes last. Thus the fields of this instructions are:

    names (bits)op (6)rs (5)rt (5)immediate (16)
    contents (decimal)8 0 9 4
    contents (binary)00100000000010010000000000000100
    contents (by 4's)0010  0000  0000  10010000  0000  0000  0100

    So the hex digits are: 20090004. This instruction remains unchanged no matter where it appears in memory, so the fact that it is loaded at 00400020 makes no difference.

    Only two instructions depend on location information: first j done, which needs to use the absolute address: 00400020hex + 3210 = 00400020hex + 20hex = 00400040hex. The jump instruction keeps this number (without the two low order binary 0's) in the low order 26 bits of the instruction itself, so it has 400040hex >> 2 = 100010hex in the low 26 bits. Putting in the opcode for a jump gives the whole instruction in hex: 08100010hex.

    The instruction la $t1, A depends on the starting address of the array A, which is 10010000hex. This is a pseudo instruction in which the 32-bit constant must be assembled from two instructions. First a lui $t1, 0x1001 and then an ori $t1, $t1, 0x0000. These when converted to machine language (with some effort) become 3C091001hex and 35290000hex. (This last ori instruction is just oring 0, so it could be deleted in this special case.)


  6. Question (Tue Nov 30 22:30:14 CST 2004): For the 2nd part of the recitation, I'm puzzled as to why the following line doesn't work with spim on pandora, but does work with spim on the linux machines...

    if I run it on pandora I get:

    Answer: The spim on the Linux machines is a later version, for a more advanced model of MIPS, and has some extra features including extra instructions, in particular, sqrt.d. (Some other parts are just different, but not an addition.) The third edition of your text is oriented toward this more recent verions of spim.