In this lab, we will write and execute a program that will copy a portion of a given array into a portion of another array, in reverse order.
The Program Template
Download the source file from here: labexam_template.spim Back to Top
#Lab Exam: Copy the elements of an array into another. # # Given arrays a and b, each 10 words long, copy elements # a[2] through a[6] (including both a[2] and a[6]) into b[8] # through b[4] in reverse order (e.g. the value in a[3] gets copied # into b[7] and a[4] into b[6]). # # The address of a[0] is being loaded into register $s0 # The address of b[0] is being loaded into register $s1 # # Complete the code so that the data values are correctly copied # from a into b. You must use a loop to iterate through the loads # and stores (no hardcoding of the addresses for the loads and stores) - # failure to use a loop will result in 0 points. #Assembler Directives .data 0x10010000 .word 23 # a[0] .word 6 .word 11 .word 7 .word 44 .word 32 .word 9 .word 16 .word 29 .word 13 .data 0x10010040 .word 6 # b[0] .word 22 .word 9 .word 1 .word 3 .word 15 .word 10 .word 4 .word 30 .word 8 .text .globl main # Code section main: add $s0, $zero, $zero lui $s0, 0x1001 # $s0 contains the address of a[0] add $s1, $s0, $zero # $s1 contains the address of b[0] ori $s1, $s1, 0x0040 ################################################################## # Insert your code here ################################################################## Back to Top
Given arrays a and b, each 10 words long, copy elements a[2] through a[6] (including both a[2] and a[6]) into b[8] through b[4] in reverse order (e.g. the value in a[3] gets copied into b[7] and a[4] into b[6]). The address of a[0] is being loaded into register $s0 The address of b[0] is being loaded into register $s1 Complete the code so that the data values are correctly copied from a into b. You must use a loop to iterate through the loads and stores (no hardcoding of the addresses for the loads and stores) - failure to use a loop will result in 0 points. Back to Top
Once you have saved the program template, you can write the code, assuming that the base address of array a is in $s0 and the base address of array b is in $s1. Details about executing the program can be found in the Lab 1 page. Note: Once you find that you have to make changes to your code, make the changes in a text editor, then reinitialize the simulator [Simulator -> Reinitialize], and load the file again [File->Open]
Turn in your code by emailing it to the TA, Matt, at mpatitz@iastate.edu. The subject line of your email should be "ComS 321 Lab Exam" and you should paste the assembly code into the message body.
Alternatively, if there is time you may demo the correct functioning of you program to Matt upon completion and it can be graded immediately.
In this lab, we have implemented code to copy a subset of array values from one array into another, in reverse order. This lab exam is worth a total of 30 points.
|