所以我有以下汇编语言代码,我需要将其转换为 C。我对几行代码感到困惑。
我知道这是一个for
循环。我在每一行都添加了我的评论。
我认为for
循环是这样的
for (int i = 1; i > 0; i << what?) {
//Calculate result
}
测试条件是什么?我该如何改变它?
查看汇编代码,变量'n'有什么作用?
这是 Intel x86 所以格式是 movl = source, dest
movl 8(%ebp), %esi //Get x
movl 12(%ebp), %ebx //Get n
movl $-1, %edi //This should be result
movl $1, %edx //The i of the loop
.L2:
movl %edx, %eax
andl %esi, %eax
xorl %eax, %edi //result = result ^ (i & x)
movl %ebx, %ecx //Why do we do this? As we never use $%ebx or %ecx again
sall %cl, %edx //Where did %cl come from?
testl %edx, %edx //Tests if i != what? - condition of the for loop
jne .L2 //Loop again
movl %edi, %eax //Otherwise return result.