Reputation: 37
I have the following code in C
int bitIndex = hash_str(input, i);
hash_str
is just a function that I call. input
is a pointer to a char
and i
a standard integer.
I'd like to implement this function in MIPS. I've determined that input
= $a0
and i
= $s0
(I've saved $s0
on the stack already).
Conventional wisdom tells me when it comes to calling functions I'd just
ARG I
ARG II
jal LABEL
My dilemma here is that $a0
and $s0
already 'exist', so how do I call the hash_str
function with them? Furthermore, how do I store that in an integer all in MIPS?
Upvotes: 0
Views: 521
Reputation: 26656
The C compiler will follow the standard calling conventions, though may have some options for different behavior.
Generally speaking first int
or pointer type parameter goes in $a0
, second in $a1
, third in $a2
, fourth in $a3
. int
or pointer type return values goes into $v0
.
The order of populating the registers doesn't matter as long as the right values have been placed in the right registers before the call instruction (jal
). So, you can first put argument 2 in $a1
, then next put argument 1 in $a0
, and it will still work the same.
For more information see here: https://www.dyncall.org/docs/manual/manualse11.html and scroll down to your architecture & ABI.
Upvotes: 1