Re: LZ: Rotating
[Prev][Next][Index][Thread]
Re: LZ: Rotating
On Mon, 29 Jul 1996, Lance Bradley wrote:
> that's pretty neat, but i'm new to asm, so , could somebody give me an example of when
> this would be used?--thanks
Everybody will probably give you their favorite use for rotating
the contents of a register and I'll give you mine. But it's good
to be aware that while some instructions were included for a
specific purpose, they're your tools to use any way you like.
Rotation is real handy when you want to scroll a screen. Let's
say you want to scroll it to the right. You can pick up a byte
from the screen, rotate it right, then pick up the next byte and
rotate it right. Since the bit that got lost from the previous
byte is in the carry, it moves into the left most position on the
next byte, which is just where you want it.
Another good example is if you want to multipy an integer by 2.
If the integer is 8 bits, you can shift it left and it doubles
in value. That's all there is to it. But if it's 16 bits, you
can shift the low order byte left, which puts the lost bit in
the carry (I think this is true on a Z80) and then rotate the
high order bit left, which causes the lost high order bit from
the low order byte to shift into the low order postion in the
high order byte. And if that doesn't confuse you, nothing will. :)
Basically, rotating is the same as shifting except you get to
keep the bit that was lost in the last shift or rotate. Or, you
can set the carry to 1, shift a byte left, and you've multiplied
it by 2 and added 1. Just toy with it a little and you'll find
uses for it as they arise.
Barry
References: