Quiz2Sol - addiu $t3 $t3 4 $t3 = 4(a b – 1 c 4 2(4 points...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CDA3101 Quiz 2 Last Name ____________________ Spring 2008 First Name ____________________ Time: 10 minutes 1. (6 points) What expression does this compute and put in $t3? Show your work by writing the contents of the register changed after each instruction. (Assume a = $t0, b = $t1, c = $t2). add $t3, $t0, $t1 # $t3 = a + b addiu $t3, $t3, -1 # $t3 = a + b – 1 sll $t3, $t3, 2 # $t3 = 4 (a + b – 1) andi $t4, $t3, 0x1 # $t4 = 0 (because $t3 is a multiple # of 4 and hence even) beq $t4, $zero else # we jump to else part sub $t3, $t3, $t2 # skip j exit # skip else: add $t3, $t3, $t2 # $t3 = 4 (a + b – 1) + c exit:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: addiu $t3, $t3, 4 # $t3 = 4 (a + b – 1) + c + 4 2. (4 points) Assume for the following that variable a is in register $s0, and b is in $s1. Convert the following C fragments directly to MIPS assembly; do not optimize in any way and do not use any macroinstructions. Comment your code to indicate what each line does. a=0; for(b=10; b > 0, b = b-1) { a = a + b; } add $s0, $zero, $zero # $s0 = 0 + 0 addiu $s1, $zero, 10 # $s1 = 10 loop:beq $s1, $0, finish # if( $s1==0) go to finish add $s0, $s0, $s1 # $s0 = $s0 + $s1 (a=a+b) sub $s1, $s1, 1 # $s1 decrement by 1 j loop # go back to loop finish: # finish...
View Full Document

This homework help was uploaded on 04/18/2008 for the course CDA 3103 taught by Professor Bandyopadhyay during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online