我有一个任务需要将程序集转换为 C。程序集是 x86。我对程序集进行了注释并开始填写 C 中的空白,但我对一些事情有点迷茫,有人可以帮忙吗?请解释不要只给出我想要学习的答案。
集会:
x at %ebp+8, n at %ebp+12
1 movl 8(%ebp), %esi //store x in esi
2 movl 12(%ebp), %ebx //store n in ebx
3 movl $-1, %edi //result in edi
4 movl $1, %edx //i of loop in edx
5 .L2:
6 movl %edx, %eax //move edx to eax
7 andl %esi, %eax //sum += 1 ...? i think
8 xorl %eax, %edi //results = results ^ (i & x)
9 movl %ebx, %ecx //store n in ecx
10 sall %cl, %edx //shift edx by %cl (low byte of ecx)
11 testl %edx, %edx //check if zeroed out
12 jne .L2 //jump to .L2 if flag
13 movl %edi, %eax //move result to eax
C代码:
int loop(int x, int n) {
int result = _______;
int mask;
for (mask = 1; mask != 0; mask = ______) {
result ^= mask & x;
}
return result;
}