'How to iterate through an array in MIPS without knowing the size?
I'm working on an assignment to calculate a polynomial using loops and functions in MIPS. Basically the idea is to recreate this Java code:
public static void getPolynomial(int n, int x[], int c[] ) {
for (int i = 0; i < n; i++) {
System.out.println( "p(" + x[i] + ") = " + calcPoly(c, x[i]) );
}
}
where n is the size of the array, x[] is an array of arguments (x vals) for the polynomial, and c[] is an array of coefficients. calcPoly should calculate the polynomial given the array of coefficients and the current x-value.
I have a rough understanding of loops/functions so I think I do this given hard-coded sizes (like if I know the array size is 3, I could write calcPoly so that it calculates a 3rd power polynomial). But we have to test the program using different sized arrays, which means calcPoly will need some kind of loop right?
Given calcPoly(c, x[i]) ) is only passing in c[] and x[i], how would I get the size of c[] within calcPoly? Or am I thinking about this the wrong way? I just have no idea how to proceed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
