Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: IA32 assembly assignment

  1. Jun 27, 2008 #1
    1. The problem statement, all variables and given/known data

    //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.

    2. Relevant equations

    I have 6 registers I can use for assembly operations which are
    %eax, %edx ,%ecx,%ebx, %edi, %esi, I cannot use anything else

    3. 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
    1. The problem statement, all variables and given/known data

    2. Relevant equations

    3. The attempt at a solution
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted