Wednesday, December 18, 2024
HomeComputer programmingAssembly: Bit Rotating (Carry Flag)

Assembly: Bit Rotating (Carry Flag)

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)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!