[英]Converting IA32 Assembly to C code
I'm having some difficulty translating IA32 Assembly code back to its C code counterpart. 我在将IA32汇编代码转换回其C代码副本时遇到了一些困难。 I'm 99% of the way there, but the byte offsets and register storage are confusing me. 我的工作方式达到了99%,但是字节偏移量和寄存器存储使我感到困惑。
The assembly code in question, movl %edx, %eax
, seems to set the value stored in %eax
equal to the value in %edx
, but wouldn't that mean sub = result
? 有问题的汇编代码movl %edx, %eax
似乎将%eax
存储的值设置为等于%edx
的值,但这不意味着sub = result
吗?
I'm new to this, so your guidance is appreciated! 我是新手,因此感谢您的指导!
int d(int x, int y, int z) // x at %ebp+8, y at %ebp+12, z at %ebp+16
{
int sub, result;
sub = z - y; // movl 12(%ebp), %edx
result = sub; // subl 16(%ebp), %edx
??????????? // movl %edx, %eax
result <<= 31; // sall $31, %eax
result >>= 31; // sarl $31, %eax
result = sub * result; // imull 8(%ebp), %edx
sub ^= x; // xorl %edx, %eax
return result;
}
The first two lines of asm are actually the first line of C but reversed and performed in two parts: asm的前两行实际上是C的第一行,但颠倒了,分为两个部分执行:
sub = y; // movl 12(%ebp), %edx
sub -= z; // subl 16(%ebp), %edx
You seem to have slight trouble with the fact that at&t syntax (that this is) puts the destination operand on the right. 您似乎对at&t语法(这是)将目标操作数放在右边的事实感到有点麻烦。 As such the movl %edx, %eax
is indeed the result = sub
as written in the code. 因此, movl %edx, %eax
实际上就是代码中写入的result = sub
。 Also, the imull 8(%ebp), %edx
clearly writes into edx
so that's sub = x * result
(the eax
operand is implicit). 另外,不imull 8(%ebp), %edx
写入edx
因此sub = x * result
( eax
操作数是隐式的)。 Finally xorl %edx, %eax
is of course result ^= sub
. 最后xorl %edx, %eax
当然是result ^= sub
。 x
, which is 8(%ebp)
, is not even mentioned on that line. x
,即8(%ebp)
,在该行中甚至都没有提及。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.