1 / 6

Solution 2 nd Exam

Solution 2 nd Exam. f = f+A [2]; LW $ t0, 8($s6) ADD $s0, $s0, $ t0 B[8] = A[ i ] + A[j]; 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). for (i = 0; i < 10 ; i++)

Download Presentation

Solution 2 nd Exam

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Solution 2nd Exam

  2. f=f+A[2]; LW $t0, 8($s6) ADD $s0, $s0, $t0 • B[8] = A[i] + A[j]; 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 1 + 10*6 +2 = 63

  4. int compare(int a, int b) { if (a < b) return 1; else return 0; } COMPARE: 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: 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 jr $ra

More Related