CS61C, Spring 2010
[TA] Eric Chang - And other, more ancient ones
Due Thursday, Feb 18, 2010 @ 11:59:59pm
Last updated Wednesday, Feb. 17, 2010 @ 6:00pm
Do questions 2.15.1, 2.15.2, 2.15.4, and 2.15.5 (both part a and b) from the book (4th edition)
Do question 2.18.5 (again, both part a and b) from the book
Show the single MIPS instruction or minimal sequence of instructions for the following C statements:
b = 25 | a;
x[4] = x[5] + a;
acorresponds to register
$t0and
bcorresponds to register
$t1.
xhas a base address of 6,400,000ten that's stored in the
$t3register.
$a0is an integer argument while
$a1is a pointer to (ie: the address of) a large array. The value in
$a0can be any integer and the size of the array that
$a1points to is big enough (as long as you don't dereference memory before $a1, you won't be accessing memory that isn't yours) for the code to work correctly.
addi | $t1 $zero 31 | |
addi | $t0 $zero 31 | |
loop: | srlv | $t3 $a0 $t1 |
andi | $t3 $t3 1 | |
addi | $t3 $t3 48 | |
sub | $t4 $t0 $t1 | |
add | $t2 $a1 $t4 | |
sb | $t3 0($t2) | |
beq | $t1 $zero done | |
subi | $t1 $t1 1 | |
j | loop | |
done | sb | $zero 1($t2) |
jr | $ra |