flat assembler
Message board for the users of flat assembler.

Index > Main > Problem with equ and data.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
Fasmw 1.73
Code:
                xyzz dd  20
                xyzz equ 10
;in code
mov     ebx,xyzz    ;=10
mov     eax,[xyzz] ;=[10]
    

In this case i know problem, but in big code i easy make mistake with equ and similar data name.

In macro we have display , this can help know what do.
Did for EQU exist similar mechanism ?
Or for name EQU fasmw auto apply to name symbol '?'
mov ebx,xyzz?


Last edited by Roman on 05 Jul 2022, 09:13; edited 2 times in total
Post 05 Jul 2022, 08:57
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 650
Location: Russia
macomics
Code:
                xyzz dd  20
                xyzz equ 10
;in code
match name,xyzz { display `name, 13, 10 } ; display 10
mov     ebx,xyzz    ;=10
mov     eax,[xyzz] ;=[10]    


Code:
                xyzz dd  20
;               xyzz equ 10
;in code
match name,xyzz { display `name, 13, 10 } ; display xyzz
mov     ebx,xyzz    ;=xyzz
mov     eax,[xyzz] ;=[xyzz]    
Post 05 Jul 2022, 09:07
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
Quote:

match name,xyzz { display `name, 13, 10 } ; display 10

I have 2700 names in my game.
match its too much !
Post 05 Jul 2022, 09:10
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
Now i think do this if equ name:
Code:
eq.xyzz EQU 10 or xyzz? EQU 10    


or using
Code:
macro EQU? chName,val { chName#? EQU val }
     xyzz dd 25
EQU? xyzz,10

mov     ebx,xyzz?    ;=10
mov     eax,[xyzz] ;=[xyzz]  
    


Last edited by Roman on 05 Jul 2022, 10:47; edited 4 times in total
Post 05 Jul 2022, 09:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18844
Location: In your JS exploiting you and your system
revolution
You need a naming convention.

e.g.: Make all equ as uppercase, and all data addresses as lowercase.
Post 05 Jul 2022, 09:14
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 650
Location: Russia
macomics
or add the prefix eq to each name if it is specified via equ
Post 05 Jul 2022, 09:54
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1462
Location: Toronto, Canada
AsmGuru62
Naming convention is a "must have" thing in a large ASM project.
Always go for Object-Oriented approach -- hold on! -- when I say that, I mean that the code should be organized into objects.
I do not mean that you need to have virtual methods, if you do not want to.

As an example: assume that you need an array of pointers to anything, which dynamically grows as needed (I can't imagine a large project without it).

So, you need a structure to hold the data for that object, let us call it: "CVector".
Now, you can have two files for that object:
Code:
CVector.Inc
CVector.Asm
    

Now, put your structure into INC file:

Code:
struct CVector
        Count           dd ?    ; # of pointers in 'Array'
        Reserved        dd ?    ; # of slots available in 'Array'
        GrowBy          dd ?    ; # of slots to grow the 'Array' if room is needed for new items
        Array           dd ?    ; pointer to an array of DWORDs, where each DWORD is a pointer to anything else
ends
    

Now put your functions which will be working with that object into ASM file.
Every function should begin with the name of the object:
Code:
proc CVector_construct
        ;
        ; your code here...
        ;
        ret
endp

proc CVector_add_item
        ;
        ; your code here...
        ;
        ret
endp

proc CVector_remove_item
        ;
        ; your code here...
        ;
        ret
endp

proc CVector_insert_item
        ;
        ; your code here...
        ;
        ret
endp

proc CVector_find_item
        ;
        ; your code here...
        ;
        ret
endp

proc CVector_destruct
        ;
        ; your code here...
        ;
        ret
endp
    

Now, you can include these files into other large projects and reduce your development time.
Also, if you are not using some functions declared with proc/endp, their code is never included into final EXE file -- a very nice FASM feature!
Post 05 Jul 2022, 15:27
View user's profile Send private message Send e-mail Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 575
Location: Ukraine
Overclick
Quote:

if you are not using some functions declared with proc/endp, their code is never included into final EXE

Same as macros.
Post 05 Jul 2022, 23:35
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: 18844
Location: In your JS exploiting you and your system
revolution
If you are only using equ for numeric values then change them to use =.
Code:
xyzz dd  20
xyzz = 10 ; fasm will show an error if you try to declare it twice.    
Post 06 Jul 2022, 03:54
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 688
Location: Russian Federation, Sochi
ProMiNick
for peoples that tractate couse of same symbol in assembly & preproce time as great feature but not as problem(Roman, thanks, thanks, thanks for finding that feature):
Code:
hello = 25234
define hello +hello
hello=5; "+hello=5"got Illegal instruction error    

what could help?
Code:
macro IgnoreSymbolRedefinition statement {
        tmp equ
        tmp2 equ
        irps n,statement \{
                match any,tmp \\{ tmp2 equ tmp2 \n \\} ; if 1st symbol already grabbed grab & concantenate the rest with resolving (presense of \ infront of n mean resolving of symbol)
                match ,tmp \\{ define tmp n\\} \} ; if not grabbed 1st symbol grab it and don`t resolve it (absense of \ infront of n mean absense of resolving)
        tmp tmp2  }    

now
Code:
hello = 25234
define hello +hello
IgnoreSymbolRedefinition hello=5; now all OK    

one more: equ use preproc symbols with same name in definition while define use assembly time symbols
by the analogy of IgnoreSymbolRedefinition resolvation filter behavior could be made construction with mixed behavior (some args would be resolved and some not)
Post 06 Jul 2022, 08:31
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
I check define.
Code:
define xyz 10
xyz dd 25 ;fasm get error 10 dd 25
    
Post 06 Jul 2022, 11:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18844
Location: In your JS exploiting you and your system
revolution
define is the same as equ. It is a preprocessor text assignment.

Just use =.
Post 06 Jul 2022, 11:11
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1246
Roman
Quote:
Just use =.

sometime = not help.
Code:
define hrutt +xmm1,/xmm2,-xmm3 ;ok
hrutt = +xmm1,/xmm2,-xmm3 ;fasm error
hrutt EQU +xmm1,/xmm2,-xmm3 ;ok
    
Post 06 Jul 2022, 13:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18844
Location: In your JS exploiting you and your system
revolution
Okay, then it can't work if you use it like that.

Your initial example showed only numeric values.

Then you need a better naming convention. It is confusing to have two things named the same. Save yourself the confusion and name them differently.
Post 06 Jul 2022, 14:01
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.