Assembly: Bit Rotating (Carry Flag)

Posted June 15, 2006 by William_Wilson in Computer programming

The following tutorial describes how to shift bits left or right by a desired number of places, with a wrap-around to the other side through the carry flag.


This method saves all bits.
For instance, if you shifted AX by eight, in either direction, the new AX value would hold AH as the old AL, and AL would become the old AH.
This method is a more precise way as it does not involve a copy, in most cases. Instead, it uses the carry bit to rotate the bits.

To shift left (in this case by eight):

rcl AX,8

To shift right (in this case by eight):

rcr AX,8

You simply provide the two operands:
1) the register to shift
2) the number of places to shift

*NOTE: With this method, if the shift is one, the overflow flag will be set and thus an error. If the shift is more than one, then flag becomes undefined and will be assumed false.

Questions/Comments: [email protected]
-William. ยง (marvin_gohan)

The Conversation

Follow the reactions below and share your own thoughts.