Shift and Rotate Instructions
Shift and Rotate Instructions
Instructions
CH#7-(A_KHALIQ)
SHL (Shift Left) Instruction
Shifts each bit to the left, filling the lowest bit with 0. The
highest bit is moved to the carry flag. The bit that was in
carry flag is lost.
Permitted operands:
SHL dest,1
SHL dest,CL
SHL dest, immed8 ;80286 and higher
Desination operand can be 8, 16 or 32 bit register or memory
operand. CH#7-(A_KHALIQ)
SHL (Shift Left) Example
CH#7-(A_KHALIQ)
SHR (Shift Right) Instruction
Shift each bit to the right, replacing the highest bit with a 0. The
lowest bit is copied into the carry flag and the bit that was in
carry flag is lost.
CH#7-(A_KHALIQ)
SAL (Shift Airthmatic Left)
– Similar to SHL
CH#7-(A_KHALIQ)
SAR Shift Arithmetic Right
(for signed numbers)
Shift each instruction to the left and make a copy of the sign bit.
CH#7-(A_KHALIQ)
Rotate Instructions
ROL (rotate Left)
Moves each bit to the left. The highest bit is copied both
into carry flag and into the lowest bit.
CH#7-(A_KHALIQ)
RCL (Rotate Carry Left)
Shifts each bit to the left and copies the highest bit into the
Carry Flag, Carry Flag previous value is copied into lowest
bit of result.
CLC ;CF = 0
mov bl,88h ;BL = 10001000b
rcl bl,1 ;BL = 00010000b CF = 1
rcl bl,1 ;BL = 00100001b CF = 0
CH#7-(A_KHALIQ)
RCR (Rotate Carry Right)
Shift each bit to the right and copies the lowet bit into carry flag.
The carry Flag copies into the highest bit of the result.
stc ; CF =1
mov ah,10h ;AH = 00010000b, CF = 1
rcr ah,1 ;AH = 10001000b, CF = 0
CH#7-(A_KHALIQ)