CS201 Lab: SPIM Addressing Modes

Objective of this lab:


	To practice using base addressing to implement arrays 
	in PCSpim. You will also use loops.

Preparation


	Read lab lecture notes.

Lab Assignment

Please note:
To make it easier for marking, you are required to submit one .pdf file and all the .s files.
The .pdf file will contain all the required components for the lab assignment.
This will apply to Lab #7 to Lab #10.

Program Loop2:

Complete the SPIM assembly language program loop2.s.
  1. The program will calculate the sum of the elements in "numbers"
    whose value is less than or equal to 1000.
  2. Here is the program skeleton; you will complete it.
  3.  
    
    ##
    ## 	Program Name:	loop2.s 
    ##
    ##		- will calculate the sum of all elements in the array "numbers"
    ##		  whose value is less than or equal to 1000.
    ##		- "numbers" is an array with 5 integer elements.
    ##		- "count" holds the number of elements in "numbers".
    ##		
    ##		
    ##		- Output format must be 
    ##		  "sum = 11"
    ##
    ##		$t0 - points to array elements in turn
    ##		$t1 - contains a count of elements
    ##      	$t2 - contains sum
    ##		
    ##		$t3 - each word from the array "numbers" in turn
    ##
    
    #################################################
    #                                               #
    #               text segment                    #
    #                                               #
    #################################################
    
            .text
            .globl __start
    __start:                # execution starts here
    
    
    #	Put your answer between dashed lines.
    #
    #------------------Your code starts next line---------------
    
    
    
    
    
    #-----------------Your code ends above this line----------------
    
    	la $a0,endl	# syscall to print out
    	li $v0,4	# a new line
    	syscall 
    
    	li $v0,10	# Exit
    	syscall		# Bye!
    
    
    #################################################
    #                                               #
    #               data segment                    #
    #                                               #
    #################################################
    
            .data
    	numbers:	
    		.word 3, 2000, 2, 6, 3000
    	count:	.word 5
    	
    	ans1:	.asciiz "sum = "
    	endl:	.asciiz "\n"	   
    
    ##
    ## 	end of file loop2.s
    
    
    
  4. Print out the sum in this format: "sum = 11"

Program Average:

Write a program called Average.s
##
##	- The program will ask the user to enter 10 numbers and 
##	  store the numbers as an array of words in the memory.
##	- The program will call a function/procedure CalAvg to 
##	  find the average of the array elements.
##	- The function/procedure CalAvg will return the average 
##	  of the array elements to the calling function.
##	- Print the calculated average (returned from the function CalAvg) 
##	  in the calling function.
##	- Use these testing values for the assignment submission:
##	  10, 20, 30, 40, 50, 60, 70, 80, 90, 100
##

You will hand in the following:

  1. The source code in the files loop2.s and Average.s
  2. The screenshot to show the screen right after you loaded the .s file.
  3. The screenshot of the console displaying the corresponding results


Copyright: Department of Computer Science, University of Regina.