汇编:如何知道何时声明局部变量?

时间:2014-10-13 03:39:41

标签: assembly

我正在查看一份学习指南,其中包含以下问题和答案:

Q. Write the corresponding C code
int decode2(int x, int y, int z)
1: movl 16(%ebp), %eax
2: movl 12(%ebp), %edx
3: subl %eax, %edx
4: movl %edx, %eax
5: imull 8(%ebp), %edx
6: sall $31, %eax
7: sarl $31, %eax
8: xorl %edx, %eax

Answer:
int decode2(int x, int y, int z) {
int t1 = y - z;
int t2 = x * t1;
int t3 = (t1 << 31) >> 31;
int t4 = t3 ˆ t2;
return t4;
}

我绝不会猜到通过查看汇编代码创建的4个局部变量。是否有一些明显的方法可以说明我没有注意到? 一个相关的问题:你怎么知道返回哪个变量?在这种情况下,它是t4。

编辑:找到我的第二个问题的答案 - %eax用于返回值。

0 个答案:

没有答案