;SHL(ShiftLeft):逻辑左移
;SHR(ShiftRight):逻辑右移
;SAL(Shift ArithmeticLeft): 算术左移
;SAR(Shift Arithmetic Right): 算术右移
;其中的 SHL 和 SAL 相同, 但 SHR 和 SAR不同.
;SHL、SAL: 每位左移, 低位补 0, 高位进CF
;SHR: 每位右移, 低位进 CF, 高位补 0
;SAR: 每位右移, 低位进 CF, 高位不变
;它们的结果影响OF、SF、ZF、PF、CF
;它们的指令格式相同:
SHL r/m, i8
SHL r/m, CL
; Test24_1.asm
.386
.model flat, stdcall
includewindows.inc
includekernel32.inc
includemasm32.inc
includedebug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.code
main proc
;SHL、AL
mov al, 11100111b
shl al,1
PrintHexal ;CE -11001110b
sal al, 2
PrintHexal ;38 -00111000b
mov al,11100111b
mov cl,2
shl al,cl
PrintHexal ;9C -10011100b
;SHR
moval, 11100111b
shral, 2
PrintHexal ;39 -00111001b
;SAR
mov al, 11100111b
sar al,2
PrintHexal ;F9 -11111001b
ret
main endp
end main
ROL、ROR、RCL、RCR: 循环移位指令
;ROL(RotateLeft): 循环左移
;ROR(RotateRight):循环右移
;RCL(Rotate through CarryLeft): 带进位循环左移
;RCR(Rotate through Carry Right):带进位循环右移
;ROL: 循环左移, 高位到低位并送CF
;ROR: 循环右移, 低位到高位并送CF
;RCL: 循环左移, 进位值(原CF)到低位, 高位进CF
;RCR: 循环右移, 进位值(原CF)到高位, 低位进CF
;它们的结果影响 OF、CF
;它们的指令格式相同:
SHL r/m, i8
SHL r/m, CL
; Test24_2.asm
.386
.model flat, stdcall
includewindows.inc
includekernel32.inc
includemasm32.inc
includedebug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.code
main proc
;ROL
mov al, 11000011b
rol al,1
PrintHexal ;87 -010000111b
;ROR
mov al, 11000011b
ror al,1
PrintHexal ;E1 -11100001b
;RCL
clc
mov al,10101111b
rcl al,1
PrintHexal ;5E -01011110b
stc
mov al,10101111b
rcl al,1
PrintHexal ;5F -01011111b
clc
mov al,10101111b
rcl al,2
PrintHexal ;BD -10111101b
;RCR
clc
mov al,11101011b
rcr al,2
PrintHexal ;BA -10111010b
ret
main endp
end main
SHLD、SHRD: 双精度移位
;SHLD(Double-Precision ShiftLeft): 双精度左移
;SHRD(Double-Precision Shift Right): 双精度右移
;SHLD 和 SHRD 有三个操作数
;操作数三: 是移位数目
;操作数一:是目的操作数
;SHLD左边被移出的位由操作数二相同数目的高位填充
;SHRD右边被移出的位由操作数二相同数目的低位填充
;操作数二不变,且须是寄存器
;它们的结果影响OF、SF、ZF、PF、CF
;它们的指令格式相同:
SHLD r16/32/m16/m32, r16/32,i8
SHLD r16/32/m16/m32, r16/32,CL
; Test25_3.asm
.386
.model flat, stdcall
includewindows.inc
includekernel32.inc
includemasm32.inc
includedebug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.code
main proc
;SHLD
mov ax, 1100110011110000b
mov dx,1111111100000000b
shld ax, dx,2
PrintHexax ;33C3-0011001111000011b
;SHRD
mov ax, 0000111100110011b
mov dx,0000000011111111b
shrd ax, dx,2
PrintHexax ;C3CC-1100001111001100b
ret
main endp
end main