int sarl_n(int x, char n){
x <<= 2;
x >>= n;
return x;
當我和 「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
爲什麼是gcc使用 「迷你寄存器」 %cl
代替大一號%ecx
?
編輯:我用O2選項以獲得更短的彙編代碼
這對優化的目的我想:8位長CL%是更好的存儲小的結果比16位%ECX。 –
嘗試用'-O2'選項組裝它以接收更明智的輸出。 – zx485
@kiner_shah:我懷疑它是爲了優化目的_,因爲沒有'-Ox'選項,它不會得到優化(很多)。我想這是一些轉換塊的原始輸出。 – zx485