Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwise shift #27

Open
rpocc opened this issue Apr 20, 2020 · 1 comment
Open

Bitwise shift #27

rpocc opened this issue Apr 20, 2020 · 1 comment
Milestone

Comments

@rpocc
Copy link

rpocc commented Apr 20, 2020

Evolving the idea of implementing the bitwise shift operators I could suggest a syntax for such shifting:
First of all, I think logical shift is a lot more used and more abstract and common operation that arithmetic shift right because the latter can be implemented through the first but not vice versa.

Possible notation can be like this:
LSR v,n 'v: value, n: number of bits
LSL v,n 'v:value, n: number of bits
So, it's variable-modifying logical shift right or left.

Also, if 6502 can't do logical shift to variable amount of bits, this can be shrinked to just ope-operand command like LSR v / LSL v

Another approach is the opposite, self-containing function like LSR(v,n) / LSL(v,n), returning the result of non-destructive logical shift. The functional approach is of course more universal because it could be used in expressions.

And the third approach is just copying C language: through binary operators << and >>. I suspect that operators in basic are actually macros for functions in a generalized form, so I believe there's shoudnt' be much difference between making it either way and the operator approach should be the most powerful, intuitive and readable.

@dmsc
Copy link
Owner

dmsc commented Apr 21, 2020

I'm liking more the "LSL()" and "LSR()" functions, or as you said that all shifts should be "logical", perhaps "SHR()" and "SHL()" would be even better. Also, it is simpler (and uses less memory) to implement only shifts by one.

Implementing the C syntax is possible, but even if I like C, I think that BASIC should not be like C :)

I mean, BASIC should be a language without too much symbols and easier syntax.

Note that this is the implementation of the current shift left in FastBasic:

.proc   EXE_USHL ; AX = AX * 2 (UNSIGNED)
        asl
        tay
        txa
        rol
        tax
        tya
        jmp     next_instruction
.endproc

It really shows how bad the 6502 is at 16bit arithmetic :-P

@dmsc dmsc added this to the v5.0 milestone Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants