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

Allow 'anonymous' forward/backward references #35

Open
ZornsLemma opened this issue May 31, 2018 · 0 comments
Open

Allow 'anonymous' forward/backward references #35

ZornsLemma opened this issue May 31, 2018 · 0 comments

Comments

@ZornsLemma
Copy link
Collaborator

ZornsLemma commented May 31, 2018

Mentioned in passing by davidgiven in #32:

numbered labels with forward/backward references. This allows things like cmp #7; beq 1f; jsr fnord; .1 without needing to open a scope or think about a label name.

Would probably be a good idea to discuss possible syntax over on stardot for something like this, though if one syntax turns out to be much easier to implement than another that would be a strong argument for it IMO. :-)

As a random thought, the ACME assembler (https://github.com/martinpiper/ACME) uses '+' and '-' symbols for this, e.g.

;*
;* SHIFT TOS-1 RIGHT BY TOS
;*
SHR     STY     IPY
        LDA     ESTKL,X
        CMP     #$08
        BCC     ++
        LDY     ESTKH+1,X
        STY     ESTKL+1,X
        CPY     #$80
        LDY     #$00
        BCC     +
        DEY
+       STY     ESTKH+1,X
        SEC
        SBC     #$08
++      TAY
        BEQ     +
        LDA     ESTKH+1,X
-       CMP     #$80
        ROR
        ROR     ESTKL+1,X
        DEY
        BNE     -
        STA     ESTKH+1,X
+       LDY     IPY
        JMP     DROP

A reference to a label consisting of nothing but '+'s always resolves to the next such label in the code, and a label consisting of nothing but '-'s always resolves to the previous such label in the code. It's not an error to have multiple '+'/'-' labels with the same name, because this rule means they're not ambiguous.

(Code fragment taken from PLASMA: https://github.com/dschmenk/PLASMA)

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

1 participant