flat assembler
Message board for the users of flat assembler.

Index > Main > Please!! sizeof.(structure) implement directly into Fasm!!

Author
Thread Post new topic Reply to topic
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 23 Aug 2004, 12:30
Overloading the struc operator works... most of the time. But when i want to have a constructor for my structure, then it is impossible to define sizeof.(structure) into a macro, or at least very troublesome.

For example, lets say i have
Code:
struc point x,y {
  .x dd x
  .y dd y
}
    


I'd like the ability to just have sizeof.point to say 8 automatically, without me having to write a macro that defines .size and stuff.

This would be most useful when putting structures into dynamic memory or into the stack. Such as
add esp, sizeof.point*3 + 4*3 + 2*1 ; 3 points, 3 doublewords, one word

Thank you for listening / debating.

And yes, i know the work around macro, but it does have its limitations.
Post 23 Aug 2004, 12:30
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 23 Aug 2004, 12:38
Hi Dragontamer,
the macros are flexible, for example, I never use sizeof.thing but instead the form thing.size that I find nicer.

In order to start a debating, it would be interesting to have examples for limitations of struct macro in order to solve (if possible) each one of them.
Post 23 Aug 2004, 12:38
View user's profile Send private message Yahoo Messenger Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 23 Aug 2004, 13:02
Ok, then how to allocate memory on the stack? Or how to allocate memory from malloc call?

sizeof.point is much cleaner than
mypoint.size

Especially if there aren't any handy points around to steal size from.

For example:
I wish to do:
Code:
function:
push ebp
mov ebp, esp
sub esp, (amount of space to allocate)
virtual at esp
  point1 point
  x dd ?
  y dd ?
end virtual

;function
mov esp, ebp
pop ebp
ret
    

Or a better example

Code:
push sizeof.point
call malloc
add esp, 4
    


True, i can just do push mypoint.size, however, it makes more sense to do sizeof.point IMO.
Post 23 Aug 2004, 13:02
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 23 Aug 2004, 13:14
This is the flexibility of structure macros that disallows the "sizeof"-like features to be build in. Suppose you have such structure:
Code:
struc mystruct string,cptrs
 {
   .String db string,0
   .Pointers rd cptrs
 }    

What would the sizeof.mystruct mean, then?

You can try to adapt "struct" macro for the structures with parameters, but you still have to allow the structure to accept empty parameters for it to work:
Code:
macro struct [def]
{
   common
   struc def {
}

macro struct_helper name
{
   virtual at 0
   name name
   sizeof.#name = $ - name
   name equ sizeof.#name
   end virtual
}

ends fix } struct_helper

struct point x,y
  .x dd x+0
  .y dd y+0
ends point

push sizeof.point    


There are also other, much more complex macro solutions.


Last edited by Tomasz Grysztar on 12 Jun 2005, 09:33; edited 1 time in total
Post 23 Aug 2004, 13:14
View user's profile Send private message Visit poster's website Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 23 Aug 2004, 13:22
Well, that makes sense...
I guess i'll just have to settle with doing mypoint.size for now.
Post 23 Aug 2004, 13:22
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 23 Aug 2004, 18:24
Dragontamer wrote:
I guess i'll just have to settle with doing mypoint.size for now.


Or sizeof.point if you prefer. That's the standard way as Privalov have indicated.
Post 23 Aug 2004, 18:24
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Aug 2004, 20:13
dragontamer: keep in mind "struc" is same as "macro", only with all names starting with "." character prepended by structure name. It is not like HLL strucgture definition.
Post 23 Aug 2004, 20:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 24 Aug 2004, 03:14
HLL structure means "compiler",
While assembler is assembler.

parsing, more-higher-abstraction, bison, flex, RTL(reigster transfer language), treecc, BNF, machine code generation, microcode, regex..

so means not only "sugar-syntax".

--
PS: *_< at least, In my short knowledge. Smile
Post 24 Aug 2004, 03:14
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.