Jump to content
Sign in to follow this  
RetroFiends

Bitwise and Batari Basic

Recommended Posts

Is there a source somewhere, or someone out there that can further elaborate bB's bitwise operations?
Specifically, I'm trying to figure out if it's possible to do a bit shift rotation within bB.

Share this post


Link to post
Share on other sites

I'm not the definitive answer. From what I've seen you need inline assembly. I mean, you could do a bunch of:

 

foo{0} = foo{1}

 

statements but it's slower than inline asm.

Share this post


Link to post
Share on other sites

It's possible to shift bits in pure bB, so long as you're not looking for the carry bit to do something useful. Just multiply or divide by the relevant powers of two

 

myvar=myvar*2 : rem shifts bits in myvar one position to the left

myvar=myvar/2 : rem shifts bits in myvar one position to the right

myvar=myvar*4 : rem shifts bits in myvar two positions to the left

myvar=myvar/4 : rem shifts bits in myvar two positions to the right

myvar=myvar*8 : rem shifts bits in myvar three positions to the left

myvar=myvar/8 : rem shifts bits in myvar three positions to the right

...

 

If you want to use the carry bit (i.e. you want to shift in bits that were shifted out) then you'll need to drop in the relevant assembly code, as accousticguitar suggests.

  • Like 1

Share this post


Link to post
Share on other sites

I guess batari figured it wasn't worth reinventing all of the opcodes in bB, since it's easy enough to drop asm into it.

 

e.g.

[some bB code here]

  asm
  rol myvariable
end

[more bB code here]
  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the responses guys. This looks like the one instance where using asm is actually easier ;)

Edited by RetroFiends

Share this post


Link to post
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.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...