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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern