homework2-fa2008

homework2-fa2008 - CSE 331: Computer Organization and...

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

View Full Document Right Arrow Icon
CSE 331: Computer Organization and Design Fall 2008 Homework #2 Points: 10 (Pair programming assignment) Due: 11:55 PM, Thursday, Sept 11, 2008 Using SPIM, write a program that sums up the first or last n elements of a data array. As shown in the assembly code below, a 10-word data array is allocated in the data segment in memory; it contains ten integers. The first three instructions starting from label main: ask the user to input a 1 to indicate that the summation should start at the beginning of the array ( item ) and work forward, or a -1 to indicate that the summation should start at the end of the array ( last ) and work backwards. The next three instructions ask the user to input the integer n between 0 and 10. If the integer is 0, the program is to return 0; else, it should sum up the first or last n elements of the data array and return the sum. The result should be stored in register $t2 and then printed out. (Hint: you can use instruction la $s0, item to load the address of the first word of the array into register $s0.) Complete the assembly program shown on the next page and submit, via ANGEL, the
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 10/01/2008 for the course CMPEN 331 taught by Professor Bhat during the Fall '08 term at Penn State.

Page1 / 2

homework2-fa2008 - CSE 331: Computer Organization and...

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