Assembly: Bit Rotating (carry flag)

Contributor Icon Contributed by William_Wilson Date Icon June 15, 2006  
Tag Icon Tagged: Computer programming

Shift bits left or right by a desired numebr of places, with a wrap around to the other side through the carry flag


This method saves all bits.
Say you shifted AX by 8, 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, but rather uses the carry bit to rotate the bits.

Shift left (in this case by 8):

rcl AX,8

or to Shift right (in this case by 8):

rcr AX,8

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

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

Questions/Comments: william_a_wilson@hotmail.com
-William. ยง (marvin_gohan)

Previous recipe | Next recipe |
 
blog comments powered by Disqus