leal 运用实例
1. 示例 1(leal 用于计算)
这里使用 C 语言和汇编代码对比
- int arith(int x,int y, int z){
- int t1 = x+y;
- int t2 = z+t1;
- int t3 = x+4;
- int t4 = y*48;
- int t5 = t3 + t4;
- int rval = t2*t5;
- return rval;
- }
- #4(%esp)存储储存着参数x,8(%esp)存储储存着参数y,12(%esp)存储储存着参数z
- movl 4(%esp), %ecx #ecx = x
- movl 8(%esp), %edx #edx = y
- leal (%ecx,%edx), %eax # eax = x + y (t1)
- leal (%edx,%edx,2), %edx # edx = 3*y
- sall $4, %edx # edx = edx << 4 (t4)
- addl 12(%esp), %eax # eax = z + t1 (t2)
- leal 4(%ecx,%edx), %edx # edx = x+4 + t4 (t5)
- imull %edx, %eax # eax = t5 + t2 (ravl)
2. 实例 2
- int logical(int x,int y){
- int t1 = x^y;
- int t2 = t1 >> 17;
- int mask = (1<<13) - 7;
- int rval = t2 & mask;
- return rval;
- }
- movl 8(%esp), %eax # 将Y的值赋值给eax
- xorl 4(%esp), %eax # x与Y进行异或运算,结果赋值给eax
- sarl $17, %eax # 给t1进行17位的算数右移,结果赋值给eax
- andl $8185, %eax # 8185是1左移13位减去7的结果,在编译之前就计算得出的