Shift and Rotate Operations
Shift and Rotate Operations
The SHR instruction is an abbreviation for ‘Shift Right’. This instruction simply shifts the mentioned bits
in the register to the right side one by one by inserting the same number (bits that are being shifted) of
zeroes from the left end. The rightmost bit that is being shifted is stored in the Carry Flag (CF).
The SAR instruction stands for ‘Shift Arithmetic Right’. This instruction shifts the mentioned bits in the
register to the right side one by one, but instead of inserting the zeroes from the left end, the MSB is
restored. The rightmost bit that is being shifted is stored in the Carry Flag (CF).
1
Syntax: SAR Register, Bits to be shifted
Example: SAR BX, 5
The SHL instruction is an abbreviation for ‘Shift Left’. This instruction simply shifts the mentioned bits
in the register to the left side one by one by inserting the same number (bits that are being shifted) of
zeroes from the right end. The leftmost bit that is being shifted is stored in the Carry Flag (CF).
The SAL instruction is an abbreviation for ‘Shift Arithmetic Left’. This instruction is the same as SHL.
2
5) ROL: Rotate Left
The ROL instruction is an abbreviation for ‘Rotate Left’. This instruction rotates the mentioned bits in the
register to the left side one by one such that leftmost bit that is being rotated is again stored as the rightmost
bit in the register, and it is also stored in the Carry Flag (CF).
The ROR instruction stands for ‘Rotate Right’. This instruction rotates the mentioned bits in the register
to the right side one by one such that rightmost bit that is being rotated is again stored as the MSB in the
register, and it is also stored in the Carry Flag (CF).
3
7) RCL: Rotate Carry Left
This instruction rotates the mentioned bits in the register to the left side one by one such that leftmost bit
that is being rotated it is stored in the Carry Flag (CF), and the bit in the CF moved as the LSB in the
register.
This instruction rotates the mentioned bits in the register to the right side such that rightmost bit that is
being rotated it is stored in the Carry Flag (CF), and the bit in the CF moved as the MSB in the register.