flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > using types defined with EQU in structures

Author
Thread Post new topic Reply to topic
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Hi everybody,

Can you tell me what do I need to do, to make the following code working OK?

Code:
format  PE      gui
include 'macro/struct.inc'
...
long    equ     dd
DWORD   equ     long

struct  STRUCT_NAME
        FIELD1  long    ?
        FIELD2  DWORD   ?
ends

restore DWORD
...    


The above code just shows the idea & unfortunatelly it isn't working. I tried to define 'long' with FIX directive but still there was an error in line of definition of 'FIELD2' structure's field. After changing second EQU to FIX 'FIELD2' definition was incorrect as DWORD was exchanged with 'long'. And the worst thing is that I cannot just write "DWORD fix dd" because such writting will be done by my program which of course wont know the size of 'DWORD' or any other c++'s types defined somewhere in a c++ file. Thanks...

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 03 Dec 2006, 18:32
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7736
Location: Kraków, Poland
Tomasz Grysztar
Since macro processing is of higher precedence than symbolic variables, this cannot be done with EQU. You may do it like:
Code:
macro typedef type,base
{ struc type [v] \{ \common . base v \}
  macro type [v] \{ \common base v \} }

typedef long, dd
typedef DWORD, long

struct  STRUCT_NAME
        FIELD1  long   ?
        FIELD2  DWORD   ?
ends    
Post 03 Dec 2006, 18:59
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
At this point all I can say is: Woooow!!! That's realy impressive!
Thanks a lot.

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 03 Dec 2006, 20:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7736
Location: Kraków, Poland
Tomasz Grysztar
It may be not bad idea to include such macro in STRUCT.INC. Do you think this syntax is a good one? Using MATCH it's possible to have many alternatives, for example more C-like one:
Code:
macro typedef statement
{ match base type,statement
  \{ struc type [v] \\{ \\common . base v \\}
     macro type [v] \\{ \common base v \\} \} }

typedef dd long
typedef long DWORD    
Post 03 Dec 2006, 21:12
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Personally I think that the first version of the macroinstruction is more readable (it's code-anyway I'm not sure what does it exactly do in cases of structures-I was reading section about macros in fasm's help file but I can't learn them) and it's syntax is a bit similar to MOV's (the second argument is 'moved' to the first one).
But actually there is a problem with it, as such macro-defined types aren't working with 'LOCAL' macros in procedures & for example 'typedef DWORD, long' will cause errors if somebody will attempt to write code like 'push DWORD 5' is there any way our 'typedef' can be improved?

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 04 Dec 2006, 00:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i prefer C-compatible syntax
Post 04 Dec 2006, 00:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7736
Location: Kraków, Poland
Tomasz Grysztar
With local it doesn't work because DD is not a type that can work without given value (as types defined with "struct" do), so you have to do it like "local a: dd ?" and thus "local a: long ?".

To make it work without "?" you may define "long" type like here:
Code:
struc long v
{
  if <v> eq <>
   . dd ?
  else
   . dd v
  end if
}    

Or: redefine the "dd" this way to accept empty definition and then use "typedef" macro as above.

As for the possible conflict of DWORD macros (if you define such) with size operators, I can only advise to write the size overrides in other form than uppercase.
Post 04 Dec 2006, 17:25
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Thanks Tomasz, that's far enough. Now I just can hope that you will still support fasm so it won't 'die' as tasm did. Thanks again.

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 04 Dec 2006, 22:22
View user's profile Send private message Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
to add something like: typedef long DWORD - is a good idea.(IMHO)
Post 05 Dec 2006, 06:02
View user's profile Send private message Reply with quote
IceStudent



Joined: 19 Dec 2003
Posts: 60
Location: Ukraine
IceStudent
It's good, but if will be used C syntax.
Post 05 Dec 2006, 20:24
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 YouTube, Twitter.

Website powered by rwasa.