所以我有以下汇编语言代码,我需要转换成C.我困惑了几行代码。汇编语言到C
我知道这是一个for
循环。我在每一行添加了我的评论。
我觉得for
循环是这样
for (int i = 1; i > 0; i << what?) {
//Calculate result
}
什么是测试条件?我该如何改变它?
看看汇编代码,变量'n'做什么?
这是英特尔的x86所以格式是MOVL =源,什特
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.
testl%edx,%edx检查edx是否为0,然后jne - 如果不为零则跳转。 – 2010-10-24 12:20:38
你对哪条线感到困惑?在C中,for循环用于(;;){} – 2010-10-24 12:33:23
为什么要将legacy asm转换为C? – 2010-10-24 12:34:33