flat assembler
Message board for the users of flat assembler.

Index > Windows > Why doesn't this work? Please fix this in your next update.

Thread Post new topic Reply to topic

Joined: 07 Dec 2017
Posts: 62
Ben321 06 Jul 2018, 04:25
I have a function named Add
   some code goes here

And it is called is called like this.
push 2
push 3
call Add

This doesn't work. I get the error Invalid Operand when compiling.

However, here's the kicker. It SHOULD work. There's nothing in the official Intel x86 assembly specs that prevents an assembler from having a label that is identical to an opcode. Opcodes are not used in the same context as labels. Labels are always defined with a ":" as the last character in the label, and are always used as something OTHER THAN the first item in a line of assembly code. Opcodes always are the first item in a line of assembly code and NEVER have a colon at the end of their name.

So in no context that a label appears (either being defined, or being used) should a label be mistaken for an opcode by an assembler. There simply isn't any overlap between opcodes and labels in any context.

Therefore, there is no reason that an assembler should reject a label, as if it thinks there is some conflict between the label and an opcode of the same name. The assembler needs to do more than just look at the word being used, and also evaluate the context it is being used in. Labels never appear in the same context as opcodes.
Post 06 Jul 2018, 04:25
View user's profile Send private message Reply with quote
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 06 Jul 2018, 07:39
A label is not always followed by ":", it can also precede a labeled instruction (like data directive) or some other similar constructions specific to fasm. Since all labels are handled the same way, this restriction was chosen to prevent potential pitfalls. For example "int db +1" could be an INT instruction with "db" as just a label used for its numeric value, or it could be a DB definition labeled as "int".

At the same time fasmg does allow to use the same name for symbols of different classes (like instruction- and expression-class). This is because fasmg focuses more on allowing to re-define and customize everything in language even if this can cause potential traps for unaware. The instruction-class always has a priority, so if you define a macro called "add" you can no longer have definition like "add db ?" because that calls the "add" macro instead - but if you define an "add" label first and only apply the "add" macroinstruction later in the source you can still use "add" in expressions freely.

Actually, the same happens when you use macros in fasm 1, but there the preprocessor is a separate layer and a distinct language (while in fasmg everything is unified into a single layer).

In fasmg it also possible to use interceptor macros to detect and catch a ":" or "=" definition before the instruction get interpreted, so what you suggested could to some extent be achieved there.

PS. Now that I think of it, also the claim that "labels are always used as something other than the first item in a line" is not universally true, consider MASM's syntax of ENDP for example.
Post 06 Jul 2018, 07:39
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.