flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Need Help with struct/struc

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
I need help on this one.

I have a struct declared in data section. However whenever i create a variable with that struct instance, FASM tells me "illegal construction". can you please help me. Here's the code

Code:

include 'win32ax.inc'

section '.text'....
;;Do stuff

section '.idata' ....

section '.data' ...

struct TST

        sec DD ?
        ems  DD ?
        samples DD ?
        hms DD ?

ends 
          
tstInstance TST ; It fails here...please help me

    
Post 10 Aug 2010, 04:03
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I'm not sure why the error is detected so late that it ends catched up by something unrelated, it seems that there has to be at least one valid data instruction for it to work properly. The problem is that you used "DD" instead of "dd" inside struct. If you change only one of those DDs to dd, you'll see an error message coming from "ends".

Probably this needs fixing, so I'm moving it to Compilers Internals (it is not an error with fasm itself though, only the struct macro is wrong).
Post 10 Aug 2010, 05:06
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I think you would have to extend macro to accept uppercase also...

INCLUDE\MACRO\STRUCT.INC
Code:
   ...
   struc dd [val] \{ \common define field@struct .,dd,<val>
                             fields@struct equ fields@struct,field@struct \}
   struc DD [val] \{ \common define field@struct .,dd,<val>
                             fields@struct equ fields@struct,field@struct \}
   ...
    

I am not sure if this is the correct way to fix it though?
Post 10 Aug 2010, 18:07
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
bitshifter,
I think it is a good idea to have all possible combinations (dd, dD, Dd and DD), but that wouldn't fix the problem, the following code is not triggering the error at ends:
Code:
include 'win32ax.inc'

struct TST
       xor eax, eax
ends    
This however does:
Code:
include 'win32ax.inc'

struct TST
       field db ? ; Only difference with previous code.
       xor eax, eax
ends    
Post 10 Aug 2010, 18:28
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
But that is trying to break it...
I think instructions should not be allowed in struct.
But for OOP you should be able to define function pointers...
Code:
include 'win32ax.inc'

struct TST
       field db ?
       pfn dd do_stuff
ends

section '.code' code readable executable

do_stuff:
        xor     eax,eax

section '.data' data readable writeable

tstInstance TST
    
Post 10 Aug 2010, 19:04
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

I think instructions should not be allowed in struct.

I completely agree with that, and that is the reason for what I want the error to be ALWAYS detected, not only when at least one field definition was valid. My second code fails with an error message generated by "ends" macro saying "Error: definition of TST contains illegal instructions.", I want that error to appear in my first code too, but currently it doesn't.
Post 10 Aug 2010, 19:24
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7801
Location: Kraków, Poland
Tomasz Grysztar
LocoDelAssembly wrote:
[My second code fails with an error message generated by "ends" macro saying "Error: definition of TST contains illegal instructions.", I want that error to appear in my first code too, but currently it doesn't.
It was a bug, not an designed behavior. It is fixed in the latest packages.
Post 31 Aug 2010, 09:03
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.