SHL、SHR、SAL、SAR: 移位指令
;SHL(Shift Left): 邏輯左移
;SHR(Shift Right): 邏輯右移
;SAL(Shift Arithmetic Left): 算術左移
;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
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.code
main proc
;SHL、AL
mov al, 11100111b
shl al, 1
PrintHex al ;CE - 11001110b
sal al, 2
PrintHex al ;38 - 00111000b
mov al, 11100111b
mov cl, 2
shl al, cl
PrintHex al ;9C - 10011100b
;SHR
mov al, 11100111b
shr al, 2
PrintHex al ;39 - 00111001b
;SAR
mov al, 11100111b
sar al, 2
PrintHex al ;F9 - 11111001b
ret
main endp
end main
ROL、ROR、RCL、RCR: 循環移位指令
;ROL(Rotate Left): 循環左移
;ROR(Rotate Right): 循環右移
;RCL(Rotate through Carry Left): 帶進位循環左移
;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
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.code
main proc
;ROL
mov al, 11000011b
rol al, 1
PrintHex al ;87 - 010000111b
;ROR
mov al, 11000011b
ror al, 1
PrintHex al ;E1 - 11100001b
;RCL
clc
mov al, 10101111b
rcl al, 1
PrintHex al ;5E - 01011110b
stc
mov al, 10101111b
rcl al, 1
PrintHex al ;5F - 01011111b
clc
mov al, 10101111b
rcl al, 2
PrintHex al ;BD - 10111101b
;RCR
clc
mov al, 11101011b
rcr al, 2
PrintHex al ;BA - 10111010b
ret
main endp
end main