Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So for one of my homework assignments I was asked to translate form the assembly

ID: 3678384 • Letter: S

Question

So for one of my homework assignments I was asked to translate form the assembly code to the C code.

  

long loop (long x, int n) /*x in %rdi , n in %esi
{
  
movl %esi, %ecx
movl $1, %edx
mvl $0, %eax
jmp .L2
//.L3:
movq %rdi, %r8
andq %rdx, %r8
orq %r8, %rax
salq %cl, %rdx
// .L2:
testq %rdx, %rdx
jne: .L3
rep ret
  
}

And I concluded with this:

long loop (long x, long n)
{
long result =____ //I put n here
long mask;
for (mask = ____; mask___; mask=_____) // x, >0 , +1, really confused here
{
result |=____ //mask
}
return result
}

I was wondering if someone could give it a quick check

Explanation / Answer

First define two variable long result and long mask. Then start for loop.

You manage you for loop condition according to > or <

long loop (long x, long n)

        {

                // why you put n here because we define this variable for assign mask value in loop.

long result;//I put n here

// long variable define that we use in for loop

                long mask;

                // in for loop first we assign x value in mask then check condition with n and then mask variable increment. I use mask++ if you want then use mask=+1. Its up on you

for (mask=x; mask>n; mask++) // x, >0 , +1, really confused here. Not >0 your condation with n

                {

                                // here we assign mask value in result variable.

                                result |=mask; //mask

                }

// here we return finally result

return result;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote