Jump to content
Sign in to follow this  
M12

Quick Question: Does 7800basic have bit shift operators?

Recommended Posts

Does 7800basic have bit shift operators? I can't find them in the documentation here: http://www.randomterrain.com/7800basic.html

 

And if it doesn't, then how would I use the 7800basic "asm" command to write the 6502 assembly code to perform the operation, say, num1 << num2 (logical shift left)?

 

Thanks!

Edited by M12

Share this post


Link to post
Share on other sites

Sort of. If you multiply or divide by a power of 2, then it gets optimized into left or right shifting, respectively.

 

e.g.
 ; num1=num1*4" gets turned into this 6502 assembly...
 LDA num1
 ASL
 ASL
 STA num1

This is great for 8-bit values, but if you want to shift a 16-bit value (or more) you'll need to break out the assembly, since the multiply technique doesn't shift in any carry bits.

 

 rem 7800basic code with inline assembly...
 asm
 ;shift 16-bit value left one place
 ASL myvaluelo ; shifts all bits left one position. 0 is shifted into bit 0 and the original bit 7 is shifted into the Carry. 
 ROL myvaluehi ; shifts all bits left one position. The Carry is shifted into bit 0 and the original bit 7 is shifted into the Carry. 
end
 rem we're back to 7800basic code

Share this post


Link to post
Share on other sites

Thanks! And thanks again for letting me know about the 16-bit shift, cause I needed that too. :)

Share this post


Link to post
Share on other sites

You're welcome. I figured you'd be interested in the 16-bit version sooner or later. :)

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...