flat assembler
Message board for the users of flat assembler.

Index > Windows > Bug with Define statement

Author
Thread Post new topic Reply to topic
Ben321



Joined: 07 Dec 2017
Posts: 61
Ben321 14 Dec 2017, 13:05
I'm currently doing this, to make accessing function arguments easier.
Code:
define Arg1 ebp+8
define Arg2 Arg1+4
define Arg3 Arg2+4 
    


But then when it's used in the code, Only Arg1 works. Arg1 is correctly evaluated as ebp+8. However when Arg2 is evaluated in the actual program code, it is evaluated as literally Arg1+4. It doesn't recursively then evaluate Arg1 in order to get the correct interpretation of Arg2, which should be ebp+12. The result when FASM looks at Arg2 is that it sees the literal text Arg1+4 and has no idea what Arg1 is at this point, thinking it should be a label in the code (like if it were defined with "Arg1:"), and this causes it to give the error "undefined symbol 'Arg1'" when compiling. Please fix this bug.
Post 14 Dec 2017, 13:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19263
Location: In your JS exploiting you and your system
revolution 14 Dec 2017, 13:11
It will work with EQU:
Code:
Arg1 equ ebp+8
Arg2 equ Arg1+4
Arg3 equ Arg2+4    
But you might want to add brackets to ensure you get what you want because they are textual equates.
Post 14 Dec 2017, 13:11
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8135
Location: Kraków, Poland
Tomasz Grysztar 14 Dec 2017, 13:31
revolution wrote:
But you might want to add brackets to ensure you get what you want because they are textual equates.
For this reason it would be better to not use preprocessor at all for this purpose, just regular labels:
Code:
label Arg1 at ebp+8
label Arg2 at Arg1+4
label Arg3 at Arg2+4    


Alternatively, if you needed preprocessor's variables in order to be able to re-define them, they can be used to be just "links" to actual assembly-time symbols:
Code:
struc redefinable value
{
        local a
        label a at value
        . equ a
}

Arg1 redefinable ebp+8
Arg2 redefinable Arg1+4
Arg3 redefinable Arg2+4    
PS. With fasmg plain "=" could be used for the same purpose. It was never allowed in fasm 1, though it was not really because of any technical limitation.
Post 14 Dec 2017, 13:31
View user's profile Send private message Visit poster's website Reply with quote
Ben321



Joined: 07 Dec 2017
Posts: 61
Ben321 14 Dec 2017, 20:37
Tomasz Grysztar wrote:
Code:
label Arg1 at ebp+8
label Arg2 at Arg1+4
label Arg3 at Arg2+4    


Pretty sure that won't work. A label is used to define a fixed value, a numerical constant. A function argument is based on ebp, which is a register (its value is only known at runtime, not at compile time), and thus is not a numerical constant. Using a label would work as a numerical constant, while what I need is a string constant, so that when it is compiled it converts that string constant into the literal string I want in the pre-process stage, and then the string I want gets assembled correctly in the assembly stage.
Post 14 Dec 2017, 20:37
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8135
Location: Kraków, Poland
Tomasz Grysztar 14 Dec 2017, 20:50
Ben321 wrote:
Pretty sure that won't work. A label is used to define a fixed value, a numerical constant. A function argument is based on ebp, which is a register (its value is only known at runtime, not at compile time), and thus is not a numerical constant. Using a label would work as a numerical constant, while what I need is a string constant, so that when it is compiled it converts that string constant into the literal string I want in the pre-process stage, and then the string I want gets assembled correctly in the assembly stage.
In fasm any label can have a value being a linear polynomial with register terms. When such label is used in an instruction, fasm generates corresponding addressing mode.
Post 14 Dec 2017, 20:50
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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.