
movl 4(%edx,%edx,4), %eax:存取記憶體位址 5x+4 取值leal 4(%edx,%edx,4), %eax:計算有效位址 5x+4 存入 %eax,不存取記憶體相當於 C 語言 &i 取址操作。可用於算術運算優化 (如 leal (%eax,%eax,2), %edx 實現 3*%eax)。

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;
}
arith:
pushl %ebp
movl %esp, %ebp
movl 16(%ebp), %eax # z → %eax
leal (%eax,%eax,2), %edx # %edx = 3*z
sall $4, %edx # %edx = 48*z (左移4位=乘16)
movl 12(%ebp), %eax # y → %eax
addl 8(%ebp), %eax # %eax = x + y (t1)
andl $65535, %eax # %eax = t1 & 0xFFFF (t3)
imull %edx, %eax # %eax = t2 * t3 (t4)
popl %ebp
ret
movl 16(%ebp), %eax 取 zleal (%eax,%eax,2), %edx 計算 3z (優化乘法)sall $4, %edx 左移 4 位 → 48z (t2)movl 12(%ebp), %eax 取 yaddl 8(%ebp), %eax 計算 x+y (t1)andl $65535, %eax 取低 16 位 (t3)imull %edx, %eax 計算 t2*t3 (t4) 回傳

leal 用於乘法優化 (移位+加法)sall 左移實現乘 2 的冪次