Start your code at location 0x100. This means (256-2)/2 = 127 is the maximum number of dimensions. Your code should act as the main program, just like in assignment 2. This code must use a subroutine to multiply numbers.
(2) MIPS program to do the same computation, with dimension in $a0, address of X in $a1, address of Y in $a2. Output is via $v0, so this is the usual calling convention for the function
int dotprod(int dim, int X[], int Y[]);
Name your function dotprod. We've provided a main test routine which will call dotprod and print out the result. This test routine is by no means exhaustive; you should probably do more testing of your own. A copy of this file is in the public directory. Your MIPS code does not have to contain a subroutine. Your dotprod should be written using the standard calling convention with the proper register usage; it is a leaf function and can be treated as such as long as you register usage is correct.
Due Friday, Oct 30, 12:45pm. You may be up to 4 days late with this assignment, with the usual 0.9 factor per day.
The equivalent C code is:
int m = 100; int array[128]; int gauss(int n); void main(void) { int i; for (i = 0; i < m, i++) array[i] = gauss(i); } int gauss(int n) { int v = 0, i; for (i = 1; i <= n; i++) v = v + i; return v; }
I also showed what any compiler worth its salt ought to be able to do: write the loops in better assembler. For gauss, the faster code is:
gauss: sub $sp, $sp, 8 sw $fp, 4($sp) add $fp, $sp, 8 sw $ra, 0($fp) li $v0, 0 li $t0, 1 j gtest gloop: add $v0, $v0, $t0 addi $t0, 1 gtest: ble $t0, $a0, gloop gloop_done: lw $ra, 0($fp) lw $fp, -4($fp) add $sp, $sp, 8 jr $ra
Make sure you understand how stack frames work and why this 2nd version is faster. Figure out how this works with recursion.
bsy+www@cs.ucsd.edu, last updated