Tom Kelliher, CS 220
Due Sept. 14, 2007
sllv $s0, $s1, $s2which uses the least significant five bits of the value in register
$s2 to specify the amount $s1 should be shifted left:
.data
mask: .word 0xfffff83f
.text
start: lw $t0, mask
lw $s0, shifter
and $s0, $s0, $t0
andi $s2, $s2, 0x1f
sll $s2, $s2, 6
or $s0, $s0, $s2
sw $s0, shifter
shifter: sll $s0, $s1, 0
Add comments to the code and write a paragraph describing how it works.
Note that the two lw instructions are pseudo-instructions that use a
label to specify a memory address that contains the word of data to be
loaded. (Similarly for the sw instruction.) Why do you suppose
that writing ``self-modifying code'' such as this is a bad idea (and
oftentimes not actually allowed)?
while (save[i] == k)
i += 1;
on page 74 uses both a conditional branch and an unconditional jump each
time through the loop. Only poor compilers would produce code with this
loop overhead. Rewrite the assembly so that it uses at most one branch or
jump each time through the loop. How many instructions are executed before
and after the optimization if the number of iterations of the loop is 10
(i.e., save[i + 10] does not equal k and save[i],
save[i + 9] equal k)?