flat assembler
Message board for the users of flat assembler.

Index > Main > Inconsistent symbol processing & probable bug

Author
Thread Post new topic Reply to topic
gmg1812



Joined: 15 Aug 2014
Posts: 13
Location: Northern New York
gmg1812
If you assemble the following with fasm 1.71.39:

! db 1 ; OK
;$ db 2 ; Invalid use of symbol
;% db 3 ; Invalid use of symbol
;? db 4 ; Reserved word used as symbol
@ db 5 ; OK
^ db 6 ; OK
_ db 7 ; OK

Four of the 7 db's assemble OK, the others get the indicated errors.

However, if you assemble:

! equ 1
db !
$ equ 2
db $
% equ 3
db %
? equ 4
db ?
@ equ 5
db ?
^ equ 6
db ^
_ equ 7
db _


;! db 1 ; Reserved word used as symbol
;$ db 2 ; Reserved word used as symbol
;% db 3 ; Reserved word used as symbol
;? db 5 ; Reserved word used as symbol
;@ db 6 ; Reserved word used as symbol
;^ db 6 ; Reserved word used as symbol
;_ db 7 ; Reserved word used as symbol

The equ's all assemble OK, but all the db's get error messages, two different than in the first case.

The reason the equ's are OK is the preprocessor's tokenize code accepts them as valid symbols, but why does the assembler act differently in the two cases? Whatever characters like % and @ are, they are certainly not reserved words. I would expect the "invalid use of symbol" error instead.
Post 07 Aug 2015, 03:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17621
Location: In your JS exploiting you and your system
revolution
Code:
! equ 1
! db 2 ;<--- the same as "1 db 2"    
The preprocessor does the symbol substitution first, then the assembler sees the substituted line. So you are trying to make label names from numbers which is not allowed.
Post 07 Aug 2015, 03:57
View user's profile Send private message Visit poster's website Reply with quote
gmg1812



Joined: 15 Aug 2014
Posts: 13
Location: Northern New York
gmg1812
True, my error regarding equ's (that was pretty stupid of me). But why is

! db 1 ; OK
^ db 2 ; OK
@ db 3 ; OK

while

% db 1 ; is an invalid use of symbol?

p.10 of the documentation states that "The symbols other than symbol characters and quoted strings can be used as names, so are also called the name symbols," which allows @ ! and ^ but what about %? It is not a "symbol character".

Since $ and ? alone have special uses, I understand those errors, but perhaps the documentation should be updated to make that clear when discussing names, especially as ?x is an OK name, as is x$.

If % has a special use, what is it?
Post 07 Aug 2015, 11:54
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Some symbols are used for numeric expressions - some for other purposes.

$1000 = 0x1000 = 1000h = 4096 ($=hex value)
%10001111 = 10001111b = 8fh (%=binary value)
123o = 1010011b = 0x53 (o=octal value)

% has another meaning as repeat counter.
See section 1.2.4 numerical expressions in the manual for details.

The following chars are symbol characters and have a special meaning and can be found in the TABLES.INC of the FASM source:

Code:
symbol_characters db 27
 db 9,0Ah,0Dh,1Ah,20h,'+-/*=<>()[]{}:,|&~#`;\'
    
Post 07 Aug 2015, 12:39
View user's profile Send private message Send e-mail Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
gmg1812
Quote:
but perhaps the documentation should be updated to make that clear when discussing names

What the documentation isn't very good about is using the word symbol for what should actually be called token. Still the documentation defines what a symbol is.

It should be clear however that reserved symbols cannot become names. dword is a symbol, but not a symbol character and not a quoted string. Still it cannot become a name of an assembly time constant/variable, cause it's reserved by the assembler for other uses. The same is true for instance for numbers (note the difference between $? and ?$). And for the symbols ?, $ and % as well. x$ is a symbol and it's not reserved, hence it can be used as a name.

The above mentioned reserved symbols aren't reserved for the preprocessor and can therefore become names of preprocessor constants or macros. But the same way the reserved symbol include cannot become a name ( macro include {} fails). On the other hand it can become an assembly time constant name, cause it's not reserved by the assembler:
Code:
x equ include
x = 5

if include = 5
    display 'Works as expected',13,10
end if    


Quote:
If % has a special use, what is it?

1.2.4 Numerical expressions wrote:
There are also some special symbols that can be used inside the numerical expression. First is $ [...] The other one is %, which is the number of current repeat in parts of code that are repeated using some special directives (see 2.2) and zero anywhere else.

_________________
Faith is a superposition of knowledge and fallacy
Post 07 Aug 2015, 12:41
View user's profile Send private message Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
In other news, I just found out that FASM treats the hex number prefix 0x, alone, as zero.
Code:
if 0x = 0
        display '0x is zero!'
end if    
Post 08 Aug 2015, 00:47
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.