Download presentation

1
Solution 2nd Exam

2
**f=f+A[2]; B[8] = A[i] + A[j]; LW $t0, 8($s6) ADD $s0, $s0, $t0**

SLL $t0, $s3, 2 ADD $t0, $s6, $t0 LW $t0, 0($t0) SLL $t1, $s4, 2 ADD $t1, $s6, $t1 LW $t1, 0($t1) ADD $t2, $t0, $t1 SW $t2, 32($s7)

3
for (i = 0; i < 10; i++) a = a + b + 1; add $t0, $zero, $zero LOOP: slti $t1, $t0, 10 beq $t1, $zero, EXIT add $s0, $s0, $s1 addi $s0, $s0, 1 addi $t0, $t0, 1 j LOOP EXIT: 7 instructions total number is *6 +2 = 63

4
**int compare(int a, int b) { if (a < b) return 1; else return 0; }**

slt $t0, $a0, $a1 addi $v0, $zero, 1 bne $t0, $zero, EXIT addi $v0, $zero, 0 EXIT: jr $ra

5
int compare(int a, int b) { if (subit (a, b) <0) return 1; else return 0; } int subit (int a, int b) return a-b;

6
**COMPARE: EXIT: SUBIT: addi $sp, $sp, -4 sw $ra, 0($sp) jal SUBIT**

addi $t1, $zero, 1 slti $t0, $v0, 0 #subit(a,b)<0 -> $t0=1 bne $t0, $zero, EXIT addi $t1, $zero, 0 EXIT: add $v0, $t1, $zero lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra SUBIT: sub $v0, $a0, $a1

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google