Jump to content



1

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


5 replies to this topic

#1 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,911 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Fri May 30, 2008 11:20 PM

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, Fri May 30, 2008 11:22 PM.


#2 kenfused OFFLINE  

kenfused

    Stargunner

  • 1,192 posts
  • Location:Columbus, Ohio

Posted Sat May 31, 2008 12:01 AM

View PostRandom Terrain, on Sat May 31, 2008 12:20 AM, said:

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, Sat May 31, 2008 12:01 AM.


#3 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,911 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat May 31, 2008 12:22 AM

View Postkenfused, on Sat May 31, 2008 2:01 AM, said:

View PostRandom Terrain, on Sat May 31, 2008 12:20 AM, said:

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.atariarch.../chapter_10.php

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

#4 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,911 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat May 31, 2008 12:55 AM

View Postkenfused, on Sat May 31, 2008 2:01 AM, said:

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.

#5 kenfused OFFLINE  

kenfused

    Stargunner

  • 1,192 posts
  • Location:Columbus, Ohio

Posted Sat May 31, 2008 1:35 AM

View PostRandom Terrain, on Sat May 31, 2008 2:55 AM, said:

   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.

#6 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,911 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat May 31, 2008 4:18 PM

Maybe it works differently with playfield variables or something:

Attached File  ror_rol_example.bin   4K   27 downloads




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users