{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# HW1_sol - 2.1 op 8 35 43 8 8 4 2.6 rs 0 4 5 4 5 3 rt 2 3 3...

This preview shows pages 1–4. Sign up to view the full content.

2.1 op rs rt imme 8 0 2 0 addi \$v0, \$zero, 0 35 4 3 0 loop: lw \$v1, 0(\$a0) 43 5 3 0 sw \$v1, 0(\$a1) 8 4 4 4 addi \$a0, \$a0, 4 8 5 5 4 addi \$a1, \$a1, 4 4 3 0 -5 beq \$v1, \$zero, loop 2.6 srl \$t0, \$t3, 6 andi \$t0, \$t0, 131071 . sll \$t0, \$t3, 9 srl \$t0, \$t0, 15 2.10 let \$t1 point to the jump table, which indicates the address of k_0, k_1, k_2, and k_3 slt \$t0, \$s5, \$zero # check if k < 0 bne \$t0, \$zero, Exit # k < 0 slt \$t0, \$s5, \$t2 # check if k > 4 beq \$t0, \$zero, Exit # k > 4 sll \$t0, \$s5, 2 # k = k * 4 add \$t1, \$t1, \$t0 lw \$t0, 0(\$t1) # \$t0 = Jumptable[k] jr \$t0 # jump to k_0, k_1, k_2, or k_3 k_0: add \$s0, \$s3, \$s4 # f = i + j j Exit k_1: add \$s0, \$s1, \$s2 # f = g + h j Exit k_2: sub \$s0, \$s1, \$s2 # f = g - h j Exit k_3: sub \$s0, \$s3, \$s4 # f = i – j j Exit Exit:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2.11 a. if (k == 0) f = i + j; else if (k == 1) f = i + h; else if (k == 2) f = g - h; else if (k == 3) f = i - j; b. bne \$s5, \$zero, k_1 k_0: add \$s0, \$s3, \$s4 # f = i + j j Exit k_1: addi \$t0, \$s5, -1 bne \$t0, \$zero, k_2 add \$s0, \$s1, \$s2 # f = g + h j Exit k_2: addi \$t0, \$s5, -2 bne \$s5, 2, k_3 sub \$s0, \$s1, \$s2 # f = g - h j Exit k_3: addi \$t0, \$s5, -3 bne \$s5, 3, Exit sub \$s0, \$s3, \$s4 # f = i – j Exit: c. worst case: switch case – arithmetic: 5 data transfer: 1 conditional branch: 2 branch: 2 average cycles: 12.2 if-else - arithmetic: 4 data transfer: 0 conditional branch: 4 branch: 0 average cycles: 10.8
2.15

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

HW1_sol - 2.1 op 8 35 43 8 8 4 2.6 rs 0 4 5 4 5 3 rt 2 3 3...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online