M12 Posted August 27, 2015 Share Posted August 27, 2015 (edited) 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 August 28, 2015 by M12 Quote Link to comment Share on other sites More sharing options...
RevEng Posted August 28, 2015 Share Posted August 28, 2015 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 Quote Link to comment Share on other sites More sharing options...
M12 Posted August 29, 2015 Author Share Posted August 29, 2015 Thanks! And thanks again for letting me know about the 16-bit shift, cause I needed that too. Quote Link to comment Share on other sites More sharing options...
RevEng Posted August 29, 2015 Share Posted August 29, 2015 You're welcome. I figured you'd be interested in the 16-bit version sooner or later. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.