Help!!! OT x86 crew assemble!!!!

Discussion in 'OT Technology' started by wabash9000, Sep 30, 2008.

  1. wabash9000

    wabash9000 Active Member

    Joined:
    Dec 27, 2006
    Messages:
    14,392
    Likes Received:
    0
    Location:
    Overland Park, KS
    I don't understand x86. It just doesn't work for me. What does this code do? This is no longer a homework assignment I am just looking for help understanding what this instruction set does.
    Code:
     [FONT=Courier]foo:[/FONT][FONT=Courier]
            pushl   %ebp[/FONT][FONT=Courier]
            movl    %esp, %ebp[/FONT][FONT=Courier] 
            pushl   %edi[/FONT][FONT=Courier]
            pushl   %esi[/FONT][FONT=Courier]
            pushl   %ebx[/FONT][FONT=Courier]
            cmpl    $0, 16(%ebp)[/FONT][FONT=Courier]
            jle     .L2[/FONT][FONT=Courier]
            movl    12(%ebp), %ecx[/FONT][FONT=Courier]
            leal    1(%ecx), %edx[/FONT][FONT=Courier]
            leal    (%ecx,%ecx,4), %esi[/FONT][FONT=Courier]
            movl    $5, %ebx[/FONT][FONT=Courier]
    .L4:[/FONT][FONT=Courier]
            addl    %ebx, %edi[/FONT][FONT=Courier]
            addl    %ecx, %edx[/FONT][FONT=Courier]
            addl    %esi, %ebx[/FONT][FONT=Courier]
            movl    %edx, %eax[/FONT][FONT=Courier]
            subl    %ecx, %eax[/FONT][FONT=Courier]
            cmpl    %eax, 16(%ebp)[/FONT][FONT=Courier]
            jge     .L4[/FONT][FONT=Courier]
    .L2:[/FONT][FONT=Courier]
            movl    %edi, %eax[/FONT][FONT=Courier]
            popl    %ebx[/FONT][FONT=Courier]
            popl    %esi[/FONT][FONT=Courier]
            popl    %edi[/FONT][FONT=Courier]popl    %ebp[/FONT][FONT=Courier]
            ret[/FONT]
    and this is supposed to fill in the blanks for this but I don't get it:
    Code:
     [FONT=Courier]int foo(int x[], int k, int n)[/FONT][FONT=Courier]
    {[/FONT][FONT=Courier]
      register int i;[/FONT][FONT=Courier]
      int sum;[/FONT] 
    [FONT=Courier]  for (i= ______; ______; i= ______)[/FONT][FONT=Courier]{[/FONT][FONT=Courier]
        sum = sum + ______;[/FONT][FONT=Courier]
      }[/FONT][FONT=Courier]
      return(sum);[/FONT][FONT=Courier]
    }[/FONT] 
    can anyone help a brother out?
     
    Last edited: Sep 30, 2008
  2. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    We're not going to do your homework for you. Assembly is the exact set of instructions your computer follows to perform a task. The function you have is pretty simple. Its a for loop that is adding up some values, and returning the sum of the values. All the instructions have the form "<operator> <operand> <operand>," with some operators requiring 0, 1, or 2 operands.
     
  3. wabash9000

    wabash9000 Active Member

    Joined:
    Dec 27, 2006
    Messages:
    14,392
    Likes Received:
    0
    Location:
    Overland Park, KS
    yeah I know. The assignment is past due I am now just asking for help understanding. I know what assembly is. What I don't get is the memory registers. How do I know what is stored where?
     
  4. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    The registers are on the processor. They store whatever you put in them. So, when you're tracing the execution of an assembly program, its helpful to make a table for the registers. List them out as columns, and each time a change is made to a register, write the new value underneath the old one. At the end of execution, your registers will contain the last values in the columns of the table.
     

Share This Page