flat assembler
Message board for the users of flat assembler.

Index > Main > Is DEFINE defined?

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



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 09 Jan 2024, 00:53
I looked at FASM manual but couldn't find a definition of the "define" directive.
What does it do exactly? Can it be used to create functions like in NASM?

Also, I couldn't find anything about "sizeof".
Post 09 Jan 2024, 00:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 09 Jan 2024, 05:53
The define directive followed by the name of constant and then the value, is the alternative way of defining symbolic constant. The only difference between define and equ is that define assigns the value as it is, it does not replace the symbolic constants with their values inside it.
sizeof is not part of fasm. It is defined by the code. If you include struct.inc in your source then the struct macro will compute sizeof values.
Post 09 Jan 2024, 05:53
View user's profile Send private message Visit poster's website Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 116
Location: Italy
pfranz 09 Jan 2024, 22:25
Thank you, I wonder how I missed that paragraph.

Is it possible to define functions in FASM, like

deffunc StupidSum(x) = x+5
mov al, StupidSum(3)

which would equate

mov al, 8

?
I think that in fasmg this may be achieved with "element" ... ?
Post 09 Jan 2024, 22:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 04:51
You can make a macro for mov to parse the arguments.
Code:
macro mov args& {
        match reg =, =StupidSum =( num =), args \{
                mov reg, num + 5
        rept 0 \{\} rept 1 \{
                mov args
        \}
}

        mov     eax,StupidSum(3)
        mov     ecx,7    
Post 10 Jan 2024, 04:51
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 816
Location: Russian Federation, Sochi
ProMiNick 10 Jan 2024, 08:17
I never seen before such sequence
Code:
rept 0 \{\} rept 1 \{    
how this logic acts?
why message with incomplete macro not displayed? when match in false state part "rept 0 \{" is ignored, but how it is parsed in case of positive match? count of open brackets mismatch to count of closed ones.
Post 10 Jan 2024, 08:17
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1872
Roman 10 Jan 2024, 09:14
Why not do this?
Code:
Summ equ 5
mov eax, 3+Summ
mov eax, 10/Summ
mov eax, 5+(Summ*2-4)

    
Post 10 Jan 2024, 09:14
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1872
Roman 10 Jan 2024, 09:18
I get Idea.
EQU or some New equ must know what been before.
Code:
Ww equ2 :+5 ;using without macros and match
W2 equ2 :-4*2
mov eax, 4 Ww

    

In : we get 4
4+5

mov eax, Ww ; eax=5
mov eax, [ebx Ww] ; eax, [ebx+5]
mov eax, [edx W2] ;eax, [edx-4*2]


Last edited by Roman on 10 Jan 2024, 09:31; edited 1 time in total
Post 10 Jan 2024, 09:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 09:31
No need for equ2 since equ does exactly the same.
Code:
Ww equ +5
mov eax, 4 Ww ; 4 +5    
Post 10 Jan 2024, 09:31
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1872
Roman 10 Jan 2024, 09:32
Its nice.
Post 10 Jan 2024, 09:32
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1052
Location: Russia
macomics 10 Jan 2024, 10:37
ProMiNick wrote:
how this logic acts?
why message with incomplete macro not displayed? when match in false state part "rept 0 \{" is ignored, but how it is parsed in case of positive match? count of open brackets mismatch to count of closed ones.
I think there's a typo there.
Code:
macro mov args& {
        match reg =, =StupidSum =( num =), args \{
                mov reg, num + 5
        rept 0 \\{\} rept 1 \{
                mov args
        \}
}    
When match is triggered, the "rept 0 \\{" construct opens. It will skip the entire text to \} (the \{ of "rept 1 \{" will not be taken into account and skipped). That is, the balance of the brackets will be respected because the preprocessor simply will not notice an extra opening bracket in the block, which should be ignored.
Post 10 Jan 2024, 10:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 10:49
There is no typo in the code I posted.
Post 10 Jan 2024, 10:49
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1052
Location: Russia
macomics 10 Jan 2024, 11:03
revolution wrote:
There is no typo in the code I posted.
Take a closer look. I fixed it. But the fact that your version also works suggests that fasm has problems with parentheses. It takes into account one closing parenthesis twice. For macro and for rept 0
Post 10 Jan 2024, 11:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 11:10
There is no problem with fasm either. It works as intended. There was nothing to fix.
Post 10 Jan 2024, 11:10
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 11:17
To gain a better understanding of the code, remember that the opening braces don't need to be escaped. I only escape them for readability. So you only need to consider the closing braces.
Post 10 Jan 2024, 11:17
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1052
Location: Russia
macomics 10 Jan 2024, 11:19
Here is your option
Code:
        match reg =, =StupidSum =( num =), args \{
                mov reg, num + 5
        rept 0 \{\}    
So rept 0 \{ opens a block ending in } in the external block
Here is my option
Code:
match reg =, =StupidSum =( num =), args \{
                mov reg, num + 5
        rept 0 \\{\}    
So rept 0 \\{ opens a block ending in \} in the external block
That is, in your version, the closing bracket for rept 0 will be the bracket for macro, and in my version, the bracket for rept 1.

Or take the trouble to explain the logic of working with incomplete blocks.

revolution wrote:
To gain a better understanding of the code, remember that the opening braces don't need to be escaped. I only escape them for readability. So you only need to consider the closing braces.
I see.
Post 10 Jan 2024, 11:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 11:21
There are no incomplete blocks. There is no bug in fasm parsing.
Post 10 Jan 2024, 11:21
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 12:14
Perhaps it help to realise that extraneous open braces are ignored in a block like this:
Code:
rept 0 {{{
{{{{
{{{{{{{{{{{
}    
That is valid code. No incomplete blocks.
Post 10 Jan 2024, 12:14
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 816
Location: Russian Federation, Sochi
ProMiNick 10 Jan 2024, 20:36
Try to guess: incomplete macro? illegall syntax?
Code:
match =a,a { match =b,b { match =c,c { match =d,d { match =e,e { rept 0 {}}}}}
        display 'x<>y' \}\}\}\}\}\\\\\\\\\}\\\\\\\\}\\\\\\\}\\\\\\}\\\\\}\\\\}\\\}\\}\} }    

succesfully compiled, just not display 'x<>y'.
I could assume that match differs from any other preprocessor block (any enclosed in curvy brackets) - any preprocessor block started inside of successfull match block could be ended after end of parent block. so in above example previously closed all matches in same order as they started and rept 0 closed by last curvy bracket not prepended by \, because at that moment it become not nested - all parents are closed.
Tomasz, that is not a bug - is a good bug, even best pleasant bug - a feature. But could thou explain it or atleast make that feature documented.
moreover we could manage order of closed blocks (that is useless but we could):
Code:
match =a,a { match =b,b { match =c,c { match =d,d { match =e,e { rept 0 {\\\\}}\\}}}
        display 'x<>y' \}\}\}\}\}\\\\\\\\\}\\\\\\\\}\\\\\\\}\\\\\\}\\\\\}\\\\}\\\}\\}\} }    
Post 10 Jan 2024, 20:36
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20486
Location: In your JS exploiting you and your system
revolution 10 Jan 2024, 21:46
ProMiNick wrote:
Try to guess: incomplete macro? illegall syntax?
No.
ProMiNick wrote:
succesfully compiled, just not display 'x<>y'.
Because you have rept 0.

Works as intended. You asked for no repetitions, you got no repetitions.

You only have to consider the closing braces. Each closing brace that is encountered is the end point for that macro block. The code I posted has two blocks. The first "match" block, and the second "rept 1" block. The first "match" block, if matched, will output a final "rept 0" to suppress the second "rept 1" block.
Post 10 Jan 2024, 21:46
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 816
Location: Russian Federation, Sochi
ProMiNick 10 Jan 2024, 21:59
that isn`t answered why syntaxes of successful match differ from unsucessfull one(and from all preprocessor blocks) or anybody could bring example where else parent preprocessor block closed before its descendant, its descendant closed outer of parent and that everithing not caused incomplete macro.
Post 10 Jan 2024, 21:59
View user's profile Send private message Send e-mail 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.