Do I see this correctly:
In Func1, you call Func2
which calls Func1 again
which calls Func2 again
which calls Func1 again
which calls Func2 again
...
Stack overflow, resulting in bad memory access and segmentation fault
Obviously, don't do that :). What do you want to do, exactly? Return result of multiplication from Func2? Then return it, just like you return result of addition from Func1.
Then the assignment clearly says:
call Func2 as though it were Func2(Q). Func2 should double its input argument and send that doubled value back
So why do you give Func2 two arguments? If we assume valid assignment, then you can work on it small pieces, like this piece I quoted. It says Func2 needs 1 argument, so trust that and make Func2 with one argument, and you have one piece of assigment done (then if it turns out assignemnt is invalid or tries to trick you, you need to get back to it, of course, but above is pretty clear).
But to help you, you have working code, right?
.global Func
Func: save %sp,-800, %sp
add %i0, -45 , %l0
mov %l0, %i0
ret
restore
And for Func2, you need to change that code so it multiplies by two, instead of adding -45? Have you tried changing the add instruction to:
imul %i0, 2 , %l0
(or umul, but in your C code you specify int
and not unsigned int
, so I presume it is signed...).
I'm not going to write your Func1
for you, but you see how you get your inputs, which I assume is right. Then you need to produce result in %i0
before returning. Work in small steps: first make Func1
which returns just %i0 + %i1
without calling Func2
at all. Then try 2 * %i0 + %i1
, calling Func2
once. Then finally write requested version of 2 * %i0 + 2 * %i1
calling Func2
twice (or for less and simpler code, extract the common factor so you still need to call Func2
just once).