Difference between SHL and SAL in 80x86

烂漫一生 提交于 2019-11-29 05:28:00

According to this, they are the same:

The shift arithmetic left (SAL) and shift logical left (SHL) instructions perform the same operation; they shift the bits in the destination operand to the left (toward more significant bit locations). For each shift count, the most significant bit of the destination operand is shifted into the CF flag, and the least significant bit is cleared (see Figure 7-7 in the Intel®64 and IA-32 Architectures Software Developer'sManual, Volume 1).

Both were probably included just for completeness since there is a distinction for right-shifts.

There's no difference apart from Intel and AMD wanting to deprecate the duplicate SAL.

shl and sal are the same.They have same machine code.
shr and sar are NOT the same.They have almost same machine code.(but not)
Check this.

they work the same, since an arithmetic shift is the same as a bitwise shift when it's to the left (increasing). sar, on the other hand, will be different from shr if the sign bit is set.

They are the same if you use the left direction.

I would also have a look at the table in the Intel 64 and IA-32 Architectures Software Developer's Manuals Volume 2 "SAL/SAR/SHL/SHR—Shift" which contains a table with:

D0 /4             SHL r/m8, 1
REX + D0 /4       SHL r/m8**, 1
D2 /4             SHL r/m8, CL
REX + D2 /4       SHL r/m8**, CL
C0 /4 ib          SHL r/m8, imm8
REX + C0 /4 ib    SHL r/m8**, imm8
D1 /4             SHL r/m16,1
D3 /4             SHL r/m16, CL
C1 /4 ib          SHL r/m16, imm8
D1 /4             SHL r/m32,1
REX.W + D1 /4     SHL r/m64,1
D3 /4             SHL r/m32, CL
REX.W + D3 /4     SHL r/m64, CL
C1 /4 ib          SHL r/m32, imm8
REX.W + C1 /4 ib  SHL r/m64, imm8

D0 /4             SAL r/m8, 1
REX + D0 /4       SAL r/m8**, 1
D2 /4             SAL r/m8, CL
REX + D2 /4       SAL r/m8**, CL
C0 /4 ib          SAL r/m8, imm8
REX + C0 /4 ib    SAL r/m8**, imm8
D1 /4             SAL r/m16, 1
D3 /4             SAL r/m16, CL
C1 /4 ib          SAL r/m16, imm8
D1 /4             SAL r/m32, 1
REX.W + D1 /4     SAL r/m64, 1
D3 /4             SAL r/m32, CL
REX.W + D3 /4     SAL r/m64, CL
C1 /4 ib          SAL r/m32, imm8
REX.W + C1 /4 ib  SAL r/m64, imm8

By comparing both parts, we see that each operand choice has the same encoding for both SHL and SAL, so they are identical.

Mystical's quote follows in the same section further confirming it.

actually both are same ..! but SAL Used when numeric multiplication is intended EXAMPLE SAL:

Multiply AX by 8
MOV CL, 3
SAL AX, CL

BOTH ARE MOSTLY WORK SAME AND HAVE SAME MACHINE CODE

Please take a look at this:

http://en.wikibooks.org/wiki/X86_Assembly/Shift_and_Rotate

While SHL/SHR do an unsigned rotation, SAL/SAR do a signed rotation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!