CS61CL, Summer 2009
[TA] James Tu
Due Monday, July 13, 2009 @ 9:30 am
Changes to the spec will be indicated in red.
If you copied hw4q5.txt before July 9, 2009, please go back and copy that file again.
Note that you will need to create the file cod.txt.and hw4q4.txt.
Add your answers to cod.txt.
Add your answers to cod.txt.
Add your answers to cod.txt.
3rd Edition P&H 2.30. If you don't have the 3rd edition, here is the problem. Write the C equivalent:
The following code fragment processes two arrays and produces an important value in register$v0. Assume that each array consists of 2500 words indexed 0 through 2499, that the base addresses of the arrays are stored in
$a0and
$a1respectively, and their sizes (2500) are stored in
$a2and
$a3, respectively. Add comments to the code and describe in one sentence what this code does. Specifically, what will be returned in
$v0?
Also, convert this MIPS code to C (you may find it easier to understand if you do this first!).
sll | $a2, $a2, 2 | |
sll | $a3, $a3, 2 | |
add | $v0, $zero, $zero | |
add | $t0, $zero, $zero | |
outer: | add | $t4, $a0, $t0 |
lw | $t4, 0($t4) | |
add | $t1, $zero, $zero | |
inner: | add | $t3, $a1, $t1 |
lw | $t3, 0($t3) | |
bne | $t3, $t4, skip | |
addi | $v0, $v0, 1 | |
skip: | addi | $t1, $t1, 4 |
bne | $t1, $a3, inner | |
addi | $t0, $t0, 4 | |
bne | $t0, $a2, outer |
Add your answers to hw4q4.txt.
Translate the following MIPS instructions (which copies a string from $s0 to $s1) to their corresponing number represtations:
1 main: addiu $t0 $zero 0 2 loop: addu $t1 $s1 $t0 3 addu $t2 $s2 $t0 4 lb $t3 0($t1) 5 sb $t3 0($t2) 6 addiu $t0 $t0 1 7 bne $t3 $zero loop |
Add your solution to the file located at ~cs61c/code/hw4q5.txt. There a section for each line number which is labeled according to the line number and instruction text. In each section, include the binary representation of the instruction, with spaces demarcating the logical divisions in the instruction. Also include a list of what the names of the different parts of the instruction are followed by the decimal value contained in that section. For example, if this was the line of code I was translating:
1 main: add $t7 $t8 $t9 |
Then this would be my answer for that line:
================================ 1 main: add $t7 $t8 $t9 ================================ 000000 11000 11001 01111 00000 100000 Type: R op: 0 rs: 24 rt: 25 rd: 15 shamt: 0 funct: 32 |