Exam 2 Review Questions (with Answers)

This is representative of the kinds of topics and kind of questions you may be asked on the exam. In addition to this practice exam, you should also review:

Questions

  1. What values (in decimal) will be in registers $t0, $t1, and $t2 after this program executes?
    		
    		li $t0, 15
    		li $t1, 5 
    		addu $t2, $t0, $t1
    		
    		
    Answer:
             $t0: 15, $t1: 5, $t2: 20
             


  2. What values (in signed decimal) will be in registers $t0 and $t1 after this program executes?
    		
    		li $t0, 7
    		li $t1, 11
    		subu $t0, $t0, $t1
    		
    		
    Answer:
             $t0: -4, $t1: 11
             


  3. What values (in signed decimal) will be in registers $t0, $t1 and $t2 after this program executes?
    		
    		li $t0, 6
    		li $t1, 5
    		nor $t2, $t0, $t1
    		
    		
    Answer:
             

    $t0: 6, $t1: 5, $t2: 8 (6 = (28 0s) 0110, 5 = (28 0s) 0101, (28 0s) 0110 | (28 0s) 0101 = (28 0s) 0111, ~ (28 0s) 0111 = (28 1s) 1000, (28 1s) 1000 = 4294967288). Note This question isn't fair because of how big the decimal number is; I originally neglected the 28 0s to the left.



  4. What values (in signed decimal) will be in registers $t0, $t1 and $t2 after this program executes?
    		
    		li $t0, 12
    		li $t1, 4 
    		multu $t0, $t1
    		mflo $t2
    		
    		
    Answer:
             $t0: 12, $t1: 4, $t2: 48
             


  5. What values (in signed decimal) will be in registers $t0, $t1 and $t2 after this program executes?
    		
    		li $t0, 14
    		li $t1, 4
    		divu $t0, $t1
    		mflo $t2
    		
    		
    Answer:
             $t0: 14, $t1: 4, $t2: 3, keep in mind this is integer division
             


  6. What will the following program print, if run with SPIM?
    		
    		li $a0, 83
    		li $v0, 1
    		syscall
    		
    		
    Answer:
             83
             


  7. What values (in decimal) will be in register $t0 after this program executes?
    		
    		li $t0, 3
    		ori $t0, $t0, 8
    		
    		
    Answer:
             $t0: 11 (3 = 0011, 8 = 1000, OR yields 1011 = 11)
             


  8. What values (in decimal) will be in register $t0 after this program executes?
    		
    		li $t0, 7
    		andi $t0, $t0, 13
    		
    		
    Answer:
             $t0: 5 (7 = 0111, 13 = 1101, AND yields 0101 = 5)
             


  9. What values (in decimal) will be in register $t0 after this program executes?
    		
    		li $t0, 8
    		xori $t0, $t0, 11
    		
    		
    Answer:
             $t0: 3 (8 = 1000, 11 = 1011, XOR yields 0011 = 3)
             


  10. What will the following program print, if run with SPIM?
    		
    		li $a0, 15
    		li $v0, 1
    		syscall
    		li $a0, 'a'
    		li $v0, 11
    		syscall
    		li $a0, 4
    		li $v0, 1
    		syscall
    		
    		
    Answer:
             15a4
             


  11. What will the following program print, if run with SPIM?
    		
    		li $a0, 24
    		li $v0, 1
    		syscall
    		li $a0, 47
    		li $v0, 1
    		syscall
    		
    		
    Answer:
             2447
             


  12. What will the following program print, if run with SPIM?
    		
    		.data
    		foo:
    			  .asciiz "Some string\n"
    		bar:
    			  .asciiz "Some other string\n"
    		main:
    			la $a0, bar
    			li $v0, 4
    			syscall
    			li $v0, 10
    			syscall
    		
    		
    Answer:
             Some other string
             


  13. What will the following program print, if run with SPIM?
    		
    		.data
    		foo:
    			  .ascii "alpha"
    		bar:
    			  .asciiz "beta"
    		main:
    			la $a0, bar
    			li $v0, 4
    			syscall
    			li $v0, 10
    			syscall
    		
    		
    Answer:
             beta
             


  14. What will the following program print, if run with SPIM, and 4 is input by the user?
    		
    		li $v0, 5
    		syscall 
    		addiu $a0, $v0, 3
    		li $v0, 1
    		syscall
    		
    		
    Answer:
             7
             


  15. Convert the following C-like code into MIPS assembly. The names of the variables reflect which registers must be used for the MIPS assembly. Do not assume any initial values for the registers. You may use additional registers.
    		
    		$t0 = 3;
    		$t1 = 7;
    		$t2 = ($t0 * $t1) + 8;	 
    		
    		
    Answer:
    		 
    		 li $t0, 3
    		 li $t1, 7
    		 mult $t0, $t1
    		 mflo $t2
    		 addiu $t2, $t2, 8
    		 
             


  16. Convert the following C-like code into MIPS assembly. The names of the variables reflect which registers must be used for the MIPS assembly. Do not assume any initial values for the registers. You may use additional registers.
    		
    		int s0 = 82;
    		int s1 = s0 << 2;
    		int s2 = s1 * 20;
    		int s3 = s2 + 7;
    		int s4 = s3 - 24;
    		int s5 = s4 / 3;
    		
    		
    Answer:
    		 main:
    			li $s0, 82        # int s0 = 82;
    			sll $s1, $s0, 2   # int s1 = s0 << 2;
    			li $t0, 20        # int s2 = s1 * 20 (part 1 of 3)
    			mult $s1, $t0     # (part 2 of 3)
    			mflo $s2          # (part 3 of 3)
    			addi $s3, $s2, 7  # int s3 = s2 + 7
    			li $t1, 24        # int s4 = s3 - 24 (part 1 of 2)
    			sub $s4, $s3, $t1 # (part 2 of 2)
    			li $t2, 3         # int s5 = s4 / 3 (part 1 of 3)
    			div $s4, $t2      # (part 2 of 3)
    			mflo $s5          # (part 3 of 3)
             


  17. Convert the following C-like code into MIPS assembly. The names of the variables reflect which registers must be used for the MIPS assembly. Do not assume any initial values for the registers. You may use additional registers. The portions in <<>> will require you to use QtSpim functionality. You do not need to exit the program properly.
    		
    		int s0 = <<read integer from the user>>;
    		int s1 = s0 + 3;
    		<<print integer s1>>;
    		
    Answer:
    		 main:
    			li $v0, 5
    			syscall
    			move $s0, $v0
    			addi $s1, $s0, 3
    			
    		print:
    			li $v0, 1
    			move $a0, $s1
    			syscall