Skip to content

feat: support fasm#239

Merged
WillLillis merged 1 commit intobergercookie:masterfrom
WillLillis:fasm
Apr 13, 2025
Merged

feat: support fasm#239
WillLillis merged 1 commit intobergercookie:masterfrom
WillLillis:fasm

Conversation

@WillLillis
Copy link
Collaborator

Adds support for FASM.

cc @dsirov, if you'd still like to beta test this, I'd appreciate a second set of eyes :). I may have missed some directives from the manual.

@dsirov
Copy link

dsirov commented Apr 7, 2025

Very nice!

I am wondering about fasm-specific handling of labels (which is really great in my opnion).

  1. Labels starting with dots - are automatically local:

The label whose name begins with dot is treated as local label, and its name is attached to the name of last global label (with name beginning with anything but dot) to make the full name of this label. So you can use the short name (beginning with dot) of this label anywhere before the next global label is defined, and in the other places you have to use the full name. Label beginning with two dots are the exception - they are like global, but they don't become the new prefix for local labels.

So you can write code like this:

func1:
    ;...
    jmp .done
    ;...
.done:
    ;...
    ret

func2:
    ;...
    jmp .done
    ;...
.done:
    ;...
    ret
    

The first .done will actually be evaluated as func1.done and the second - as func2.done and they won't clash.

  1. Explicit local labels

There are some special directives available only inside the definitions of macroinstructions. local directive defines local names, which will be replaced with unique values each time the macroinstruction is used. It should be followed by names separated with commas. If the name given as parameter to local directive begins with a dot or two dots, the unique labels generated by each evaluation of macroinstruction will have the same properties. This directive is usually needed for the constants or labels that macroinstruction defines and uses internally. For example:

 macro movstr
 {
        local move
      move:
        lodsb
        stosb
        test al,al
        jnz move
}

So, in this case the move label is not global and its scope is limited to the macro (will never clash with neither move symbol external to the movstr macro nor between multiple macro invocations).

@WillLillis
Copy link
Collaborator Author

  1. Labels starting with dots - are automatically local:

That is pretty nice! I'm not sure how well we'll be able to integrate it with asm-lsp, however. The server currently does no semantic analysis; instead it relies on tree-sitter (with the tree-sitter-asm grammar) to provide features like references and goto definition. In short, all labels will be treated as globals. There may be a way to workaround this for for fasm specifically. but that'll take some time to work out and I don't want that to hold up this PR.

  1. Explicit local labels

Kind of a similar issue with point 1.

asm-lsp is written to be fairly architecture/assembler agnostic which is nice because it can support a number of different targets, but not nice because of cases like this. I'll see what I can come up with though! :)

Outside of these points, is there anything else I fix up? Otherwise, I'm planning on merging this to master this weekend. Happy to work on/fix any issues you run into afterwards too.

@WillLillis WillLillis enabled auto-merge (rebase) April 13, 2025 20:37
@WillLillis WillLillis merged commit eada85f into bergercookie:master Apr 13, 2025
14 checks passed
@WillLillis WillLillis deleted the fasm branch April 13, 2025 20:42
@WillLillis WillLillis mentioned this pull request Apr 14, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FASM support

2 participants

Comments