CDA3101-F11-Recitation03

# CDA3101-F11-Recitation03 - sw \$a1 8(\$sp jal SUM add \$t0 \$v0...

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

CDA 3101 Recitation Session 3

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

View Full Document
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; }
Solution total: addi \$sp, \$sp, -12 sw \$ra, 0(\$sp) sw \$a0, 4(\$sp)

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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.

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

## This note was uploaded on 12/10/2011 for the course CDA 3101 taught by Professor Small during the Fall '08 term at University of Florida.

### Page1 / 13

CDA3101-F11-Recitation03 - sw \$a1 8(\$sp jal SUM add \$t0 \$v0...

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

View Full Document
Ask a homework question - tutors are online