flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] Labeled Instructions

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 09 Jun 2025, 04:03
Hi, the fasmg manual Section 5 introduces "labeled instructions". Section 9 gives an example of labeled instruction: "struc some".

(BTW, I think that the methodology is clever/efficient: _define_ an instruction when the first identifier is _not_ an instruction.)

Does fasmg have a set of pre-defined instructions that can be referred to?

With regards to first identifier and its categorization e.g. as an instruction or other, does fasmg define a set of categories of what the first identifier can be? E.g. "struc" is categorized as a command and an example of a first identifier that is not an instruction. So that means first identifier can be either in the instruction category or command category. Does fasmg allow other categories for first identifier?

Do we have a reference list of predefined fasmg instructions and commands and any other identifier type that can be used as first identifier? Is this a reasonable approach to understanding what's involved in defining a labeled instruction?

Based on the definition of "labeled instruction", "struc" is a label to the instruction "some". What does this mean that "'struc' is a label to the instruction 'some'"?
Post 09 Jun 2025, 04:03
View user's profile Send private message Reply with quote
Serke



Joined: 26 Aug 2006
Posts: 7
Serke 09 Jun 2025, 17:23
"struc" itself is not a labeled instruction but a built-in fasmg command that lets you define your own labeled instructions (i.e. it's what you define using "struc" becomes a labeled instruction):
Code:
struc (lbl) assign? var*
        lbl = var
end struc
    

or
Code:
struc assign? var*
        . = var
end struc    

The code above defines the labeled instruction "assign".
Code:
myvar assign 3        ; Here "myvar" is a label to the labeled instruction "assign"

assert myvar = 3    
Post 09 Jun 2025, 17:23
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 09 Jun 2025, 19:03
Hi,

Serke wrote:
"struc" itself is not a labeled instruction but a built-in fasmg
command...

Yes, I said that struc is a command. (I didn't say that struc is a labeled instruction.)
Greg_M wrote:
..."struc" is categorized as a command...


Serke wrote:
...lets you define your own labeled instructions...

Yes, I said, based on the Section 9 example "struc some":
Greg_M wrote:
...the instruction "some".


Question #1:
Greg_M wrote:
So that means first identifier can be either in the instruction category or command category. Does fasmg allow other categories for first identifier?


Question #2:
In the term "labeled instruction" What does "labeled" mean? Based on your example, "assign", if you're saying that "struc" is not a label (I do understand that "struc" is a command), then I can understand that. So does the term "labeled instruction" mean an instruction that can be labeled? If so, then I suggest clarify that in the documentation, because the term "labeled instruction" is easily misinterpreted to mean that the label is specified as the instruction is defined.

Question #3:
What is the value/purpose of a "labeled instruction"? E.g. Does it allow it to placed in the code flow using the label as the symbol for the address?

Question #4:
Can a labeled instruction ever be used without a label?

Question #5:
Greg_M wrote:
Do we have a reference list of predefined fasmg instructions and commands and any other identifier type that can be used as first identifier? Is this a reasonable approach to understanding what's involved in defining a labeled instruction?


Thank You


Last edited by Greg_M on 09 Jun 2025, 19:43; edited 1 time in total
Post 09 Jun 2025, 19:03
View user's profile Send private message Reply with quote
dosmancer



Joined: 20 Feb 2025
Posts: 38
Location: Kingdom of Sweden
dosmancer 09 Jun 2025, 19:31
Greg_M wrote:
Question #2:
In the term "labeled instruction" What does "labeled" mean? Based on your example, "assign", if you're saying that "struc" is not a label (I do understand that "struc" is a command), then I can understand that. So does labeled instruction mean an instruction that can be labeled? If so, then I suggest clarify that in the documentation because the term "labeled instruction" is easily misinterpreted to mean that the label is specified as the instruction is defined.

In assembly language you can normally do things like this:
Code:
lbl: db $FF    

but this form is often allowed too (without colon):
Code:
lbl db $FF    

So let's say one is implementing an instruction set for the Motorola 68000 where the db equivalent is named `dc.b` instead of `db` then you can implement it like this:
Code:
macro dc.b val*
    db val
end macro

struc dc.b val*
    .:
    db val
end struc    

The reason for the 2nd one is because it allows:
Code:
some_label dc.b $FF    


That's probably where the name comes from as it often has to do with labels.

What's nice with it is that you get the label as a paramameter in the instruction body so you can really do whatever you like with it. You don't have to use it to create a label. As shown by Serke they can be used to assign values too (a non-label case of a labeled macro instruction?).

Quote:
Question #4:
Can a labeled instruction ever be used without a label?

Code:
struc lbl_instr val*
    ; something
end struc    

can never be used like this if that's what you mean
Code:
lbl_instr $FF    


A tip is to create a folder with a bunch of different small tests where you try stuff out. I found fasmg tricky to learn, especially namespaces and calminstructions for which I have many different test files.

_________________
fasm68k
Post 09 Jun 2025, 19:31
View user's profile Send private message Visit poster's website Reply with quote
Serke



Joined: 26 Aug 2006
Posts: 7
Serke 09 Jun 2025, 19:58
Greg_M wrote:
Based on your example, "assign", if you're saying that "struc" is not a label (I do understand that "struc" is a command), then I can understand that.

As I understand it, in fasmg terminology, an instruction refers to a symbol that belongs to an instruction class, while a command is a complete construct (a sentence, if you like) that fasmg recognizes and processes. A command is formed from an instruction symbol along with other components, such as labels (in the case of labeled instructions). For example, "struc" is a symbol of an instruction class while "struc some" is a command of which "struc" is part of.
Post 09 Jun 2025, 19:58
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 09 Jun 2025, 20:24
[quote="dosmancer"]
Code:
macro dc.b val*
    db val
end macro

struc dc.b val*
    .:
    db val
end struc    

The reason for the 2nd one is because it allows:
Code:
some_label dc.b $FF    


"2nd one"? As in two different means to support the dc.b ?

So, can all user-defined instructions be labeled, and the term "labeled" is simply used to emphasize that aspect? (Macros cannot be labeled?)

We seem to have multiple kinds of user-defined "instructions". I know about macro, and calminstruction. Is labeled instruction another kind? Conceptually, does the idea of supporting only one kind of user-defined instruction, have any value? I ask that, not so much to suggest it, but to gain insight.

(Studying the rest of your response, Thanks!)
Post 09 Jun 2025, 20:24
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 09 Jun 2025, 22:01
Serke wrote:
...instruction refers to a symbol that belongs to an instruction class, while a command is a complete construct (a sentence,...
Section 3 states that '=' is a command:
fasmg Manual, Section 3 wrote:
When a symbol is defined with a "=" command, ...
However, Section 5 refers to the first identifier of a command:
fasmg Manual, Section 5 wrote:
...instruction...recognized only when it is the first identifier of the command...

So, perhaps the term "command" may be used to refer to the token (e.g. '=') that is the basis of a complete command "sentence" as well as the complete command "sentence" itself.

Further:
fasmg Manual, Section 5 wrote:
If we treat "=" as a special kind of identifier, it may serve as an example of labeled instruction.

So '=' is said to be a command and also a "labeled instruction".

Can '=' be an example of "labeled instruction" because it can be in a command sentence whose first identifier is a label?

If so, is '=' more precisely classified as an "instruction" rather than a "command"?

fasmg Manual, Section 5 wrote:

...when the first identifier of the command is not an instruction - in such case the first identifier becomes a label...
Is 'struc' an instruction? One can see that from the above, that one might think that when the first identifier is not an instruction, it's a label. Yet, the manual does not state that struc is an instruction (and you said that it's a command). Perhaps someone who has experience with FASM would not be confused by the above statement in the manual. And I'm gathering that commands are also instructions.

BTW to be helpful: Typographical error in manual Section 5 "...special kind of indentifer...", "indentifer" should be "indentifier". The manual also has two other cases of this.)

In general, I think that the manual is quite thorough and explicit in one sense, but a broader vocabulary would probably help for discernment between some of the nuanced meanings. If I define my own terms for some of these nuances/overloads and if I think that they have potential value to FASM, I could post them here e.g. in a "terminology" thread (if OK with Mr. Grysztar).


Last edited by Greg_M on 10 Jun 2025, 00:05; edited 3 times in total
Post 09 Jun 2025, 22:01
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 09 Jun 2025, 23:48
From reviewing the fasmg manual further, some instructions are also called "commands". E.g. "restore" is called a command and an instruction.

fasmg Manual, Section 9 wrote:

A labeled instruction is evaluated when the first identifier of a command is not an instruction and the second identifier is of the labeled instruction class:

Question #1
What does "not an instruction" refer to? Would "struc" be considered "an instruction" in this context? I don't see "struc" referred to as an "instruction" anywhere in the fasmg manual. Is this simply a matter of the idea that "struc" is a command but commands are also part of the broader class of instructions?

Question #2
With regards to "get some" and "my POINT" in the same manual section, Section 9: are "get" and "my" both considered labels?
Post 09 Jun 2025, 23:48
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 10 Jun 2025, 00:28
Commands/Directives/Instructions are a process whereas labels and symbols are typically valued. Many instructions are the first word on a line, some instruction can work in a labeled form - as the second word of a line, and others operate in both capacities. The labeled form is invoked when the first word is not identified as an instruction.

A struc is a labeled macro.
Code:
macro try line&
end macro

struc try line&
        .: try line ; create the label, invoke the macro
end struc    
... try works as both labeled and unlabeled instruction.
Post 10 Jun 2025, 00:28
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, 00:52
I think that a flowchart for parsing the first identifier of a fasmg statement would be something like this:
Code:
Is the symbol the argument of an expression?
YES:
    Finished
NO:
    Is the symbol a command/instruction?
    YES:
        Finished
    NO:
        The symbol is a label    

Then other logic could determine if the statement is valid fasmg syntax. E.g. Is the label followed by a labeled instruction? Note that a fasmg statement can have an expression involving '=' after a label, and the fasmg manual, Section 5, indicates that the labeled instruction concept applies to such a statement. This appears to be an aid to understanding the generality of the "labeled instruction" concept, using '=' as an example, rather than a focus on the '=' command per se.


Last edited by Greg_M on 10 Jun 2025, 01:09; edited 2 times in total
Post 10 Jun 2025, 00:52
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 10 Jun 2025, 01:01
bitRAKE wrote:
Commands/Directives/Instructions are a process whereas labels and symbols are typically valued. Many instructions are the first word on a line, some instruction can work in a labeled form - as the second word of a line, and others operate in both capacities. The labeled form is invoked when the first word is not identified as an instruction.
Yes, that's helpful.

bitRAKE wrote:
The labeled form is invoked when the first word is not identified as an instruction.
The first identifier is not a label if it's an argument to command, correct? E.g. as in "x = 1"? See my flowchart, for example.
Post 10 Jun 2025, 01:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 10 Jun 2025, 01:33
Greg_M wrote:
The first identifier is not a label if it's an argument to command, correct? E.g. as in "x = 1"? See my flowchart, for example.
Is this a famous flowchart? Sorry, I'm out of the loop.

Identifier is a generic term - so is label. struc can do anything with the label:
Code:
struc pow?: n,e ; exponentiation, n^e
        repeat 1,dn:n,de:e
                if de > 0
                        local t
                        t pow dn,de shr 1
                        if de and 1
                                . = t * t * dn
                        else
                                . = t * t
                        end if
                else if de = 0
                        . = 1
                else
                        err
                end if
        end repeat
end struc    
(Or nothing.)

"x = 1" means something different if "x" is a macro.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Jun 2025, 01:33
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 10 Jun 2025, 02:22
Greg_M wrote:
I think that a flowchart for parsing the first identifier of a fasmg statement would be something like this:
Code:
Is the symbol the argument of an expression?
YES:
    Finished
NO:
    Is the symbol a command/instruction?
    YES:
        Finished
    NO:
        The symbol is a label    
Why not simply ask," Is the symbol is executable?" Which returns: yes, no, don't know.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Jun 2025, 02:22
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, 02:46
RE Flowchart: I was simply using it as an aid to understanding. Any corrections to it improve my understanding.

bitRAKE wrote:

Why not simply ask," Is the symbol is executable?" Which returns: yes, no, don't know.
For what purpose? (Are you considering args to a command [e.g. args to '='])?

Also, what do you mean by executable? Directive/Command/Instruction ?

What is "struc"? A command? An instruction? Both? Does instruction classification generally cover "executable" (based on your meaning of "executable").
Post 10 Jun 2025, 02:46
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 10 Jun 2025, 03:16
Any purpose that can be.

I thought we already established that they were a process (i.e. executable).

struc is a built in instruction, but it can be redefined - the fine-grained distinction of command/instruction/directive helps us how? Either an instruction can be changed or it can't. We can't redefine '='.

Arguments are text - which is typical for assembly macros.

If the first identifier is an instruction it will get executed and '=' becomes the start of the first argument. So, if the '=' command is executing then we known the first identifier was not executable.


Last edited by bitRAKE on 10 Jun 2025, 04:53; edited 1 time in total
Post 10 Jun 2025, 03:16
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, 03:31
bitRAKE wrote:
If the first identifier is an instruction...
By "instruction", you mean "executable/process" as you have defined in this thread?

bitRAKE wrote:
If the first identifier is an instruction it will get executed and '=' becames the start of the first argument.
'=' is not always a command?
Post 10 Jun 2025, 03:31
View user's profile Send private message Reply with quote
Serke



Joined: 26 Aug 2006
Posts: 7
Serke 10 Jun 2025, 04:31
Greg_M wrote:
'=' is not always a command?

I think bitRAKE meant this:
Code:
macro look_at_this args&
        display "'look_at_this' is called with args:      ", `args, 13
end macro

look_at_this = 3      ; This is not an assignment but a macro call! 'look_at_this' gets called with '= 3' as an argument

purge look_at_this

look_at_this = 1      ; This is not a macro call but an assignment!    
Post 10 Jun 2025, 04:31
View user's profile Send private message Reply with quote
Greg_M



Joined: 07 Jun 2025
Posts: 42
Greg_M 10 Jun 2025, 04:50
Serke wrote:

Code:
macro look_at_this args&
        display "'look_at_this' is called with args:      ", `args, 13
end macro

look_at_this = 3      ; This is not an assignment but a macro call! 'look_at_this' gets called with '= 3' as an argument

    

Serke, that explains it, thank you!

Thanks also to all on this thread.
Post 10 Jun 2025, 04:50
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 10 Jun 2025, 05:09
Greg_M wrote:
bitRAKE wrote:
If the first identifier is an instruction...
By "instruction", you mean "executable/process" as you have defined in this thread?
It's instructions all the way down - processes are just sequences of instructions (which are processes ...). This is similar to the code/data distinction made in assembly language - bytes are either intended for execution or for use by instructions.
(Rarely both - we can ignore that for now.)

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Jun 2025, 05:09
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, 05:42
fsamg Manual Section 5 wrote:
"=" may serve as an example of labeled instruction...
I'm interested in an example of this with a classification of the first identifier for the example.
Post 10 Jun 2025, 05:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.