flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] Labeled Instructions

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 10 Jun 2025, 06:07
Code:
?x = 1    
?x cannot be interpreted as an instruction-class symbol, even if an instruction named x were defined. The labeled instruction = defines a expression-class symbol named x with a value of 1.

An expression-class symbol can be used within expressions to provide a value.
Post 10 Jun 2025, 06:07
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 10 Jun 2025, 08:24
Chapter 5 was supposed to explain this, perhaps it needs an expansion.

In the manual I generally used the term "command" to refer to an operation that you expect the assembler to perform. It is not directly related to syntax. You can give command like "define a symbol with value 1" or "put a byte into the output" with numerous syntax variations.

On the other hand, by "instruction" I usually mean a specific syntax, a symbol of instruction class. This can be a built-in instruction, or a macro, or CALM instruction. All of these are instructions - symbols that a recognized when they are the first identifier of a line (or generally a statement, because if line begins with a label followed by ":", the rest is interpreted again as if this was the beginning of a new line).

The labeled instructions are another similar class of symbols, which are only recognized when being a second identifier in the line, with the first identifier being a label (and therefore interpreted as an expression-class symbol). And just like regular instructions, they can be built-in, macros (defined with "struc"), or CALM.

In fact, you could rewrite many of the built-in directives as the same instructions written in CALM, and there would be no functional difference (except for the impact on performance). The engine purposefully does not discriminate.

As for the algorithm that chooses how to interpret a line, you could describe it as follows:
  1. Is there a catch-all instruction active (like "macro ? &line&")? If yes, execute with the whole line as arguments.
  2. Does the line start with an identifier? If no, pass it to the "other syntax interceptor" (one defined with "macro ?? &line&", or default handler that just shows "illegal instruction" error).
  3. Is the first identifier a symbol of instruction class? If yes, execute it. Works the same for built-in instructions and macros.
  4. Is the second identifier a symbol of labeled instruction class, or one of the special symbols like "="? If yes, execute the labeled instruction.
  5. Otherwise pass to the "other syntax" interceptor.
However, if you look at the actual source, you will find that the algorithm is more complex, because there are also factors of assembly modes and unconditionality:
  1. Is there an unconditional catch-all? If yes, pass to it.
  2. Is the CALM definition active? If yes, use the ALM variant of this algorithm (it looks for instruction only in the special namespace, and handles labels only as CALM pointer definitions).
  3. Does the line start with an identifier? If no, go to the point 17.
  4. Is the first identifier a symbol of instruction class? If no, go to 10.
  5. Is the instruction unconditional? If yes, execute it.
  6. Is a macro currently being defined? If yes, append the line to its body and stop here.
  7. Are we inside a skipped block (like "if" with false condition, or "repeat 0")? If yes, stop processing this line.
  8. Is there a weak (conditional) catch-all? If yes, pass to it.
  9. Otherwise execute the regular (conditional) instruction.
  10. When the first identifier was not an instruction, treat it as a label. If there is an unconditional labeled instruction catch-all, pass ot it.
  11. Look at the second identifier. If there is no labeled instruction there, go to 17.
  12. Is the labeled instruction unconditional? If yes, execute it.
  13. If it's a macro definition or a skipped block, behave the same as in points 6-7.
  14. If there is a weak (conditional) catch-all, execute it.
  15. If there is a labeled instruction catch-all, execute it.
  16. Otherwise execute the labeled instruction.
  17. If inside a macro definition or skipped block, behave as in points 6-7.
  18. Is there a weak (conditional) catch-all? If yes, pass to it.
  19. If there is an "other syntax" interceptor, pass to it.
  20. Otherwise signal "illegal instruction" error.
Post 10 Jun 2025, 08:24
View user's profile Send private message Visit poster's website Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 10 Jun 2025, 23:55
Thanks kindly!
Post 10 Jun 2025, 23:55
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 11 Jun 2025, 06:08
bitRAKE wrote:
Code:
?x = 1    
Thank you for the example!

bitRAKE wrote:
?x cannot be interpreted as an instruction-class symbol...The labeled instruction = defines a expression-class symbol named x...
Logical, and an example that the first identifier can be other than a label or an instruction.
Post 11 Jun 2025, 06:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.