Assembly: Bit Rotating

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


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 is done with a temporary copy of the register which is then shifted into the blank slots as the shift occurs.

Shift left (in this case by 8):

shld AX,8

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

shrd AX,8

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

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

Previous recipe | Next recipe |
 
blog comments powered by Disqus