Homework 7 Information, ECS50 Spring 1998
- Homework due by Midnight Wednesday, June 3rd.
Assignment:
Write a subroutine capable of calculating the sum or difference of two long
integer arrays. The results should be stored in a third array. A different
subroutine should print out the result array. (For those of you that
care, this is what Vector Processors like the CRAY do for a living.)
The requirements are:
- The program should be written in MIPS assembly language and run on SPIM
(XSPIM)
- Parameters are passed using the regular MIPS convention (first 4 in regs,
rest on stack)
- The stack grows down in memory (push operations decrease the value of
the stack pointer), and the stack pointer points to the next available slot
(not the top element).
- The subroutine expects 6 parameters (in this order):
- a mode specifying whether to add or subtract
(0=add arrayA+arrayB, 1=subtract arrayA - arrayB)
- the number of elements in arrayA,
- the number of elements in arrayB,
- the address of the first array (arrayA),
- the address of the second array (arrayB),
- the address of the third array (the result array, arrayR),
- Your subroutine must not use any global variables.
- The elements of arrayR contain the result of the specified operation on
arrayA and arrayB.
Assumptions
-
Each array will not have more than 100 elements
-
You should be able to print both positive and negative numbers
-
Use the system calls to accomplish your printing
Extra Credit
-
Allow the data arrays to be entered from the keyboard (this isn't worth much!)
Examples
If arrayA = 1,34,5
and arrayB = 2,0
then arrayR = 3,34,5 (arrayA + arrayB)