assembly loop question

IT would appreciate , if you can point me in the right direction with this question.

loop:

1     pushl     %ebp
2     movl      %esp,  %ebp
3     movl      8(%ebp) , %ecx
4     movl     12(%ebp) , %edx
5     xorl      %eax , %eax
6     cmpl      %edx , %ecx
7     jle       .L4


.L6

16    decl        %ecx    
17    incl        %edx
18    incl        %eax
19    cmpl        %edx , %ecx
20    jg         .L4



.L4

21    incl        %eax
22    movl        %ebp , %esp
23    popl        %ebp
      ret          
     


Fill the blanks of the corresponding C source code.

int loop(int x int y)
{
    int result;

    for (.........;.............;result++) {

    '''''''''''''' ;
    .............. ;
   }

    ............ ;

   return .........;
}
 
lecosAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lecosAuthor Commented:


ok , this is what i understand from the code. I kinda know what is happening but im still having problems trying to express it in C code.
 Let me know if what i did is correct . thank you.

loop:

1     pushl     %ebp
2     movl      %esp,  %ebp
3     movl      8(%ebp) , %ecx          / value x is stored into % ecx /
4     movl     12(%ebp) , %edx        / value y is stored into % edx /
5     xorl      %eax , %eax               / %eax is set to zero, % eax is "result"
6     cmpl      %edx , %ecx              / compare x to y/
7     jle       .L4                                /   if   x <= y  , go  to L4 /
 

.L6

16    decl        %ecx                     /   x  = x-1  /
17    incl        %edx                      /   y  = y+1 /
18    incl        %eax                     /  result = result +1 /
19    cmpl        %edx , %ecx        /    if x > y , then keep on the loop /
20    jg         .L6                **** corrected ***  



.L4

21    incl        %eax                       /   result = result + 1 /
22    movl        %ebp , %esp
23    popl        %ebp                               return  result
      ret          
     


Fill the blanks of the corresponding C source code.

int loop(int x int y)
{
    int result;

    for (..result = 0...;... x <=y..........;result++) {
 x = x-1
    '''''''''''''' ;
    ....y = y+1.......... ;
   }

    .....result  = result + 1....... ;

   return result;
}
0
Infinity08Commented:
>>  Let me know if what i did is correct . thank you.

The assembly code interpretation looks all good, yes.

Now let's have a look at the corresponding C code.


>>     for (..result = 0...;

ok.

>> ... x <=y..........;

This should be the loop continue condition. As long as this condition is true, the loop will continue.

>> result++) {

>>  x = x-1
>>     '''''''''''''' ;
>>     ....y = y+1.......... ;
>>    }

Both ok.

>>     .....result  = result + 1....... ;

Ands this is ok too.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lecosAuthor Commented:


>> ... x <=y..........;

This should be the loop continue condition. As long as this condition is true, the loop will continue.


@@     if this condition is true , the loop will continue so     if x > y, the loop will continue.


0
Infinity08Commented:
That's better :) You've got it :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Assembly

From novice to tech pro — start learning today.