InClassActivity05-sol - 10:03 AM Activity#05(solutions...

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

View Full Document Right Arrow Icon
2/3/03 10:03 AM ECSE-2660 Computer Architecture, Networks, & Operating Systems, Spring 2003 Page 1 of 3 Activity #05 (solutions) Activity 5.1 (First hour) Learning to go from MIPS Assembler Pseudo code C Program 1. (25 points) 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 of instructions in the MIPS code. Then, create a corresponding C/C++ program, and infer the program’s behavior from the C program. a0=n begin: addi $t0, $zero, 0 t0=0 add $t1, $zero, $a0 t1=n Loop: slt $t3, $t1, $zero bne $t3, $zero, finish if(t1 < 0) go to finish add $t0, $t0, $t1 t0 = t0 + t1 addi $t1, $t1, -1 t1 = t1 - 1 j loop goto loop finish: add $t0, $t0, $t0 t0 = t0 + t0 add $t0, $t0, $t0 t0 = t0 + t0 addi $v0, $t0, 0 v0 = t0 C program: a0 = n; t0 = 0; t1 = n; while (t1 >= 0) { t0 = t0 + t1; t1 = t1 - 1; } t0 = 2*t0; t0 = 2*t0; v0 = t0; This program calculates the sum 4n + … + 12 + 8 + 4
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.

This note was uploaded on 04/25/2010 for the course ECSE ecse-2340 taught by Professor Wozny during the Spring '09 term at Rensselaer Polytechnic Institute.

Page1 / 3

InClassActivity05-sol - 10:03 AM Activity#05(solutions...

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