- #1
fsbadr
- 18
- 0
Homework Statement
//this function is the callee
int func(int num1, int num2)
{
int t = num1 * num2;
return t - (num1 + num2);
}
//this is the caller
int main()
{
int a = 4;
int b = 8;
int c = func(a, b);
return 0;
}
When caller calls callee, callee does not need to worry about overwriting
the "caller save" registers (for instance, %eax). The system ensures that
any data that caller required and that happened to be stored in these
"caller save" registers would be saved and restored for caller. However,
if callee were to overwrite any of the "callee save" registers (for instance,
%ebx), then callee first must save the current contents of any such
register and then restore the contents before returning. Assume, in the
above example, that caller and callee each requires registers for its local
int variables, parameters, and return value.
Homework Equations
I have 6 registers I can use for assembly operations which are
%eax, %edx ,%ecx,%ebx, %edi, %esi, I cannot use anything else
The Attempt at a Solution
I have done the following, if someone could help me in this
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ecx ;; addressing modes -- copy n1 into ecx
movl 12(%ebp), %edx ;; addressing modes -- copy n2 into edx
imull (%ecx,%edx), %eax ;; multiply n1 * n2
addl %ecx,%edx ;; add n1 + n2
subl %ecx,%eax ;; t - (n1 + n2) and store value in eax
movl %ebp, %esp ;; reset the stack pointer
popl %ebp ;; reset the frame pointer
ret ;; return