InClassActivity05-sol - 5:53 PM SOLUTIONS Activity#05...

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

View Full Document Right Arrow Icon
2/8/02 5:53 PM ECSE-2660 Computer Architecture, Networks, & Operating Systems, Spring 2002 Page 1 of 3 SOLUTIONS Activity #05 Activity 5.1 (First hour) Learning to go from MIPS Assembler Pseudo code C Program a. (25 pts) Describe what the following MIPS code returns in the output register $v0. Assume that $a0 is used for the input and initially contains "n", a positive integer. First, start by creating a pseudo-code description, then a C/C++ program, and infer the program’s behavior from the C program. a0=n begin: addi $t0, $zero, 0 t0=0 addi $t1, $zero, 0 t1=0 addi $t2, $zero, 0 t2=0 loop: slt $t3, $a0, $t2 bne $t3, $zero, finish if(a0 < t2 ) go to finish add $t0, $t0, $t1 t0 = t0 + t1 addi $t1, $t1, 2 t1 = t1 + 2 addi $t2, $t2, 1 t2 = t2 +1 j loop goto loop finish: addi $v0, $t0, 0 v0 = t0 C program: a0 = n; t0=t1=t2 = 0; while (a0 > t2) { t0 = t0 +t1; t1 = t1 +2; t2 = t2+1; } v0 = t0; This program calculates the sum 2 + 4 + 6 +. ....+ 2n Grading: There are 3 parts to this question: Pseudocode (10 pts), C program (10 pts), final answer (5 pts). For the 5 pt parts, give 2 pts for trying, and 5 for correct answer. For the 10-point parts, point out errors, and
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

InClassActivity05-sol - 5:53 PM SOLUTIONS Activity#05...

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

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