CDA3101-F11-Recitation03

CDA3101-F11-Recitation03 - sw $a1, 8($sp) jal SUM add $t0,...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CDA 3101 Recitation Session 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
Procedures Write the MIPS code for the corresponding procedures TOTAL and SUM. Assume the SUM procedure is represented by the label SUM, that a, b, and array A are represented by $a0, $a1 and $s0, respectively, and that array A is defined globally. int total(int a, int b) { int e; e = SUM(a, b) + (a * b) + A[4]; return e; } int SUM(int x, int y) { A[4] = y; y = y + 1; x = x + y; return x; }
Background image of page 2
Solution total: addi $sp, $sp, -12 sw $ra, 0($sp) sw $a0, 4($sp)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sw $a1, 8($sp) jal SUM add $t0, $v0, $0 lw $ra, 0($sp) lw $a0, 4($sp) lw $a1, 8($sp) addi $sp, $sp, 12 mult $a0, $a1 mflo $t1 lw $t2, 16($s0) add $v0, $t0, $t1 add $v0, $v0, $t2 jr $ra Solution SUM: sw $a1, 16($s0) addi $a1, $a1, 1 add $a0, $a0, $a1 add $v0, $a0, $0 jr $ra Loop-Post condition do { i=i+1; }while (i<10) li $t2, 10 LOOP: addi $t1, $t1, 1 sub $t3, $t1, $t2 bltz $t3, LOOP END Solution Solution Solution...
View Full Document

Page1 / 13

CDA3101-F11-Recitation03 - sw $a1, 8($sp) jal SUM add $t0,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online