Homework_2 - program. Both you and your programming partner...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 331: Computer Organization and Design Spring 2008 Homework #2 Points: 5 (Pair programming assignment) Due: 5pm, Friday, Feb. 8, 2008 Using SPIM write a program that sums up all the odd numbers or all the even numbers in 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 the ten integers from 1 to 10. The first three instructions starting from label ‘ main: ’ allow the user to input an integer. If this integer is zero, the program is to sum up all the even numbers in the data array. Otherwise, the program is to sum up all the odd numbers. The result should be stored in register $t1 and then printed out. Finish the assembly program shown below and submit, via ANGEL, the completed and tested
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: program. Both you and your programming partner should submit the program making sure to include in your comments who your partner is. (Hint: you can use instruction ‘ la $s0, item ’ to load the address of the first word of the array into register $s0.) .data .align 2 item: .word 1 .word 2 .word 3 .word 4 .word 5 .word 6 .word 7 .word 8 .word 9 .word 10 .align 0 str: .asciiz "The answer is " cr: .asciiz "\n" .text .align 2 .globl main main: ori $2, $0, 5 syscall move $t0, $2 ##### THIS SECTION OF THE CODE ##### IS TO BE COMPLETED BY YOU ##### AND YOUR PROGRAMMING PARTNER done: ori $2, $0, 4 la $4, str syscall ori $2, $0, 1 add $4, $t1, $0 syscall ori $2, $0, 4 la $4, cr syscall...
View Full Document

This note was uploaded on 09/30/2008 for the course CMPEN 331 taught by Professor Bhat during the Spring '08 term at Penn State.

Ask a homework question - tutors are online