Jump to content
IGNORED

Is it possible to shift bits from one variable into another?


Random Terrain

Recommended Posts

Is there some already built-in bitwise magic to slide bits from one variable to another? For example, could a group of bits slide off the right side of a variable and into the left side of another variable?

 

 

Thanks.

Edited by Random Terrain
Link to comment
Share on other sites

Is there some already built-in bitwise magic to slide bits from one variable to another? For example, could a group of bits slide off the right side of a variable and into the left side of another variable?

 

 

Thanks.

In ASM it would be

 

asl RightVar

rol LeftVar

Edited by kenfused
  • Like 1
Link to comment
Share on other sites

Is there some already built-in bitwise magic to slide bits from one variable to another? For example, could a group of bits slide off the right side of a variable and into the left side of another variable?

 

 

Thanks.

In ASM it would be

 

asl RightVar

rol LeftVar

Thanks. I was looking at the following page and I thought those just rotated the bits within a variable instead of passing them on to the next variable:

 

http://www.atariarchives.org/2bml/chapter_10.php

 

I must have read it wrong. Thanks for the help.

Link to comment
Share on other sites

In ASM it would be

 

asl RightVar

rol LeftVar

I couldn't get that to work quite right, so I played around with your example and this seems to do what I want:

 

   asm
  ROR LeftVar
  ROL RightVar
end

 

Thanks for getting me on the right track. This is much easier than what I tried to do in BASIC and it takes up less space too.

Link to comment
Share on other sites

   asm
  ROR LeftVar
  ROL RightVar
end

 

Thanks for getting me on the right track. This is much easier than what I tried to do in BASIC and it takes up less space too.

 

That would shift LeftVar right. The left most bit would depend on code before it.

Then it would shift RightVar to the the left. The rightmost bit would be what was in the right bit of LeftVar.

 

ASL shifts bits to the left shifting in a 0 at the rightmost bit. The leftmost bit that gets shifted out goes into the carry flag.

ROL is the same as ASL except instead of shifting in a 0 at the right most bit it shifts in the carry flag.

 

So if you have two bytes to shift left you would use

ASL byte1
ROL byte2

 

This would be the same as

CLC
ROL byte1
ROL byte2

 

LSR and ROR are similar but going to the right.

LSR byte2
ROR byte1

 

Just remember to do them in the byte order things are flowing.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...