Bec*_*hma 5 c x86 assembly gcc
int sarl_n(int x, char n){
x <<= 2;
x >>= n;
return x;
Run Code Online (Sandbox Code Playgroud)
}
当我用"gcc -m32 -S sarl_n.c"组装时,它会发出以下代码:
.cfi_startproc
movl 4(%esp), %eax
movsbl 8(%esp), %ecx
sall $2, %eax
sarl %cl, %eax #This is the part which I don't understand
ret
.cfi_endproc
Run Code Online (Sandbox Code Playgroud)
为什么gcc使用"迷你寄存器" %cl而不是大注册%ecx?
编辑:我使用O2选项来获得更短的汇编代码
zx4*_*485 12
以下行(上一版本)之所以有问题
sarl %cl, 8(%ebp) #This is the part which I don't understand
Run Code Online (Sandbox Code Playgroud)
或(当前版本)
sarl %cl, %eax #This is the part which I don't understand
Run Code Online (Sandbox Code Playgroud)
正在使用%cl而不是%ecx,SAR操作码仅支持%cl寄存器作为变量算术移位的输入(按%cl时间).
看到这里,我引用:
SAR r/m32, CL MC Valid Valid Signed divide* r/m32 by 2, CL times.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
248 次 |
| 最近记录: |