flat assembler
Message board for the users of flat assembler.

Index > Main > Declaring string constants

Author
Thread Post new topic Reply to topic
wyvern



Joined: 08 Dec 2011
Posts: 27
wyvern
Hi all.

Im trying to do some "conditional assembly" like the following:
Code:
OS_VERSION equ WinXP
;OS_VERSION equ Etc...

...

if OS_VERSION = WinXP
    ;blah...
else if OS_VERSION = Etc...
    ;other blah...
end if
    


But i get:
Quote:

error: undefined symbol 'WinXP'


I tryied with DEFINE and = instead equ, but get the same thing. Why is this?.

Another question related, can i define symbols from command line instead changing the values in the source?

_________________
Thanks
Post 14 Feb 2012, 23:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
fasm has two separate languages on top of each other: the preprocessor and then the assembler. "equ" is a preprocessor's directive, so when you define "OS_VERSION equ WinXP", then it replaces all the occurences of OS_VERSION with WinXP, so what assembler sees is:
Code:
if WinXP = WinXP    
and it signalizes an error because the WinXP is nowhere defined.

There is a couple of different solutions how you can make this work. You can define WinXP as a constant for assembler, so that it will recognize it:
Code:
OS_VERSION equ WinXP ; this is for preprocessor

WinXP = 4 ; this is for assembler

if OS_VERSION = WinXP ; after preprocessing this becomes "if WinXP=WinXP"
; ...    
The other option is to perform conditional preprocessing instead of conditional assembly, so that everything is done by preprocessor even before assembler has a first peek at the source:
Code:
OS_VERSION equ WinXP

match =WinXP, OS_VERSION {
  ; ...
}    
And one more option is to make assembler compare whether given label name is "WinXP" even when the label is not correctly defined, you can do it with "eq" operator:
Code:
OS_VERSION equ WinXP

if WinXP eq WinXP
 ;...    
This last option may be the simplest one for you to use.

wyvern wrote:
Another question related, can i define symbols from command line instead changing the values in the source?
No, because of the Same Source, Same Output principle (sometimes called SSSO in short on this forums).
Post 15 Feb 2012, 00:02
View user's profile Send private message Visit poster's website Reply with quote
wyvern



Joined: 08 Dec 2011
Posts: 27
wyvern
Oh , excelent help, thank you. Smile
Post 15 Feb 2012, 00:09
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.