Skip to content

Allow 'anonymous' forward/backward references #35

@ZornsLemma

Description

@ZornsLemma

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions