Uses for the rotate instruction
Author Message
Uses for the rotate instruction

Hi,

Could anyone give me some examples of the uses of a rotate
instruction?  I know what it does but I can't think of why
anyone would use it instead of a shift.

Thanks!
Matt Gregory

Sat, 23 Sep 2000 03:00:00 GMT
Uses for the rotate instruction

Quote:

> Hi,

> Could anyone give me some examples of the uses of a rotate
> instruction?  I know what it does but I can't think of why
> anyone would use it instead of a shift.

A good example:

ror eax, 16     ;Move the upper 16bits of EAX into AX.
;This won't destroy the original AX.

-- X-Bios

Sat, 23 Sep 2000 03:00:00 GMT
Uses for the rotate instruction

Quote:

> Hi,

> Could anyone give me some examples of the uses of a rotate
> instruction?  I know what it does but I can't think of why
> anyone would use it instead of a shift.

> Thanks!
> Matt Gregory

Swapping the two nibbles of a byte, as in:

ROL AL,4

will exchange the high digit with the low digit.

Or it can facilitate counting of the number of 1-bits in
a register.

Sat, 23 Sep 2000 03:00:00 GMT
Uses for the rotate instruction

Let's say you need a a byte to be 0 or 1, depending on a bit flag
setting. Now let's say this bit flag setting is #7 (which is often the
case). You could either shift right by 7, but that means you need to
assume a 286+ or use CL to specify the 7. Alternatively you AND with
0x7F and then rol AL, 1. More common uses are to switch
nibbles/bytes/words around. ROL AX, 8, ROL AL, 4, ROL AX, 16 switch
byte/nibble/word.

Quote:

> Hi,

> Could anyone give me some examples of the uses of a rotate
> instruction?  I know what it does but I can't think of why
> anyone would use it instead of a shift.

> Thanks!
> Matt Gregory

--
- Ray Zwitserloot.

----------------------------------------------------

Mon, 25 Sep 2000 03:00:00 GMT
Uses for the rotate instruction

Thanks for the responses everyone.  They were very insightful.

The main reason I posted that question is because I'm trying to
understand a piece of disassembled code, and it uses the rotate
instruction quite a bit, and it's interesting because I don't
think it's used in any of the ways that were mentioned.  They
must be all hardware related, but I wanted to see if there were
any algorithm related uses for that instruction.  The examples
you guys gave are very good, and I will probably use them now
that I know about them, but nothing that I'm looking at in this
current project seems to fit in with any of those.  It's almost
always rotating just a single bit, and it's usually doing it to
memory locations.  I would give an example, but I don't think it
would help much.  Anyways, thanks for all the help.  If anyone
thinks of anything else and would care to post it, I'll be