EE380 Assignment 3 Solution

  1. 100% IA32 is a CISC instruction set, but it does have some RISC-like attributes. Which of the following attributes of the IA32 instruction set is most RISC-like?
    A single instruction can copy an arbitrary size block of data from one place in memory to another
    Arithmetic instructions include sine, evaluated by a series expansion
    Both operands for arithmetic operations can be registers
    There are special instructions for managing stack frames
    Instruction encoding is variable length
  2. 100% Suppose that the variable x is kept in memory location 4000 and the content of that memory location is 42. What is the lval of x?
  3. 100% Which of the following segments of C code best describes what the following MIPS assembly code does?
    	la	$t0, x
    	lw	$t1, 0($t0)
    	la	$t2, y
    	lw	$t3, 0($t2)
    l1:	bne	$t1, $zero, l2
    	addu	$t1, $t1, $t3
    l2:	sw	$t1, 0($t0)
    

    while (x==0) { x=x+y; }
    while (x!=0) { x=x+y; }
    if (x==0) { x=x+y; }
    if (x!=0) { x=x+y; }
    x=x+y;
  4. 100% This MIPS/SPIM program includes a subroutine called myadd that performs x=(y+z);. In the space below, replace the myadd subroutine with one named myxor that will make x have the value it would get if C code like x=(y^z); were executed, i.e., the result of bitwise eXclusive-ORing y with z. You should test your routine using SPIM before you submit it, which will require merging it with a test framework like the one used in this MIPS/SPIM program -- but only submit the myxor routine here. Remember that you can and should comment your code, especially if there are any known bugs. Half off for documented bugs. :-)
  5. 100% Write a complete MIPS assembly language program that will print your email address when executed using SPIM. Hint: you will want to use the syscall for printing a string... and yes, you can use mucky to create your answer.
  6. 100% What MIPS instruction is encoded by the value 0x01894020? (Hint: take a look at the MIPS instruction set encoding in the textbook and in SPIM).
  7. 50% 50% This (now familiar) MIPS/SPIM program includes a subroutine called myadd that performs x=y+z;. In the space below, replace the myadd subroutine with one named mymul that will compute x=y*z;. (Hint: use addu because add detects overflow.) You should test your routine using SPIM before you submit it. Although there are many ways to do a multiply, here's C code for one of them that you might want to use:
    extern int x, y, z;
    
    void
    mymul(void)
    {
         /* do x = y * z the hard way... */
         int t0 = y;
         int t1 = z;
         int t2 = 0;
         int t3 = 1;
    
         while (t3 != 0) {
              if (t0 & t3) {
                   t2 += t1;
              }
              t1 += t1;
              t3 += t3;
         }
    
         x = t2;
    }
    

  8. 100% Which of the following things is not normally found in a stack frame?
    Local variables
    Global variables
    The return address
    Function argument values
    A pointer to the previous frame
  9. 100% Which of the following statements about the MIPS assembly language and instruction set discussed in class is true?
    The li instruction can load an arbitrary 32-bit constant into a register
    The .code directive is used to identify a machine code segment
    The jal instruction places the return address on the stack
    The slt $t0,$t1,$t2 instruction makes $t0=($t1<$t2)
    The blt instruction is a conditional branch-if-less-than
  10. 100% This MIPS/SPIM program includes a subroutine called myadd that performs x=(y+z);. In the space below, replace the myadd subroutine with one named mymedian that will replace the value at location x with the median value of the three words starting at x. You are implementing a 3-point median filter; for example, the median of 4, 72, 61 is 61. The three words can be the ones called x, y, and z in the previous coding problems and in your support code, but your code should not reference them that way in your solution; x[k] is the kth word -- you should reference the words by varying k from 0 to 2. You should test your routine using SPIM before you submit it, which will require merging it with a test framework like the one used in this MIPS/SPIM program -- but only submit the mymedian routine here. Remember that you can and should comment your code, especially if there are any known bugs. Half off for documented bugs. :-)


Although this is not a secure server, users are bound by the UK code of conduct not to abuse the system. Any abuses will be dealt with as serious offenses.


EE380 Computer Organization and Design.