Link to home
Start Free TrialLog in
Avatar of s476
s476

asked on

Fill in the missing parts of the C code to get a program equivalent to the generated assembly code

Consider the following assembly code:
x at %ebp+8, n at %ebp+12
1 movl 8(%ebp), %esi
2 movl 12(%ebp), %ebx
3 movl $-1, %edi
4 movl $1, %edx
5 .L2:
6 movl %edx, %eax
7 andl %esi, %eax
8 xorl %eax, %edi
9 movl %ebx, %ecx
10 sall %cl, %edx
11 testl %edx, %edx
12 jne .L2
13 movl %edi, %eax

The preceding code was generated by compiling C code that had the following
overall form:
 
my Answer I bold it can you check it and tell me if it is correct!! thanks

int loop (int x , int n)
 {
      int result = -1 ;
      int mask;

     for ( mask = 1 ; mask != 0 .;mask= mask << ( n  % 256)
     {
          result = result ^ (x & mask
     }
     return result;      
 }
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial