Okay so I have an assignment to write some mips assembly code from C code. I sorta forgot my C and just trying to remember it.
My question is about syntax. In fact my textbook used incorrect syntax, and so its a little hard for me to understand what this code is doing.
Here is the code the textbook gives. This is a function, subroutine.
There are obviously curly brackets { } missing in the if statement. Thus I have no clue what this code is supposed to do and when. I mean when does it return i, and when does it return -1?
Obviously I need to understand the code if I am to turn it into mips. Can someone please help? Thanks guys.
My question is about syntax. In fact my textbook used incorrect syntax, and so its a little hard for me to understand what this code is doing.
Here is the code the textbook gives. This is a function, subroutine.
Rich (BB code):
int find( int a[], int n, int x)
{
int i;
for (i=0; i!=n; i++)
if(a==x)
return i;
return -1;
}
There are obviously curly brackets { } missing in the if statement. Thus I have no clue what this code is supposed to do and when. I mean when does it return i, and when does it return -1?
Obviously I need to understand the code if I am to turn it into mips. Can someone please help? Thanks guys.