了解ATT汇编语言 [英] Understanding ATT Assembly Language
本文介绍了了解ATT汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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汇编版本:
ATT Assembly version of the same program:
x在%ebp + 8,y在%ebp + 12,z在%ebp + 16
x at %ebp+8, y at %ebp+12, z at %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.
我认为它将向左移动4次.为什么会这样?
I assume it is going to shift left 4 times. Why is that?
谢谢!
我也理解我困惑的部分等同于C版本的z * 48部分.
I also understand that the part I'm confused on is equivalent to the z*48 part of the C version.
我不了解的是左移4次等于z * 48.
What I'm not understanding is how does shifting left 4 times equate to z*48.
推荐答案
您错过了leal (%eax, %eax, 2), %eax
行.应用一些数学,汇编代码将读取:
You missed the leal (%eax, %eax, 2), %eax
line. Applying some maths the assembly code reads:
a := x
a := a + 2*a // a = 3*x
a := a * 2^4 // a = x * 3*16
这篇关于了解ATT汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文