[英]Understanding ATT Assembly Language
C version: C版:
int arith(int x, int y, int z)
{
int t1 = x+y;
int t2 = z*48;
int t3 = t1 & 0xFFFF;
int t4 = t2 * t3;
return t4;
}
ATT Assembly version of the same program: ATT程序版本的汇编程序:
x at %ebp+8, y at %ebp+12, z at %ebp+16 x在%ebp + 8,y在%ebp + 12,z在%ebp + 16
movl 16(ebp), %eax
leal (%eax, %eax, 2), %eax
sall $4, %eax // t2 = z* 48... This is where I get confused
movl 12(%ebp), %edx
addl 8(%ebp), %edx
andl $65535, %edx
imull %edx, %eax
I understand everything it is doing at all points of the program besides the shift left. 我知道除了左移以外,它在程序的所有方面都在做。
I assume it is going to shift left 4 times. 我认为它将向左移动4次。 Why is that? 这是为什么?
Thank you! 谢谢!
Edit: I also understand that the part I'm confused on is equivalent to the z*48 part of the C version. 编辑:我也知道,我感到困惑的部分等同于C版本的z * 48部分。
What I'm not understanding is how does shifting left 4 times equate to z*48. 我不明白的是,左移4次等于z * 48。
You missed the leal (%eax, %eax, 2), %eax
line. 您错过了leal (%eax, %eax, 2), %eax
行。 Applying some maths the assembly code reads: 应用一些数学,汇编代码如下:
a := x a := a + 2*a // a = 3*x a := a * 2^4 // a = x * 3*16
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.