flat assembler
Message board for the users of flat assembler.

Index > Main > (REQ) sizeof (data)

Author
Thread Post new topic Reply to topic
Daemon



Joined: 08 Jul 2003
Posts: 15
Daemon
Hi,
is it possible to add an asm directive which would produce a number of bytes data uses ? and also, cannot produce 'times x STRUCTNAME' structure.
ex:
Code:
struc S1
{
  .data1 dd ?
  .data2 dd ?
  .data3 rb 128
}

s1 S1

mov eax,[s1.data1]
mov ecx,sizeof s1.data1 ; should asm to mov ecx,4!
    

I tryed to play with macros & write own 'struct' macro but... nothing.
Is there a possibility to write such a macro? with every member of structure having 'sizeof' member ?
(the code is same only mov ecx,sizeof.s1.data should be there...)

Greetz,
Daemon.
Post 01 Jun 2004, 10:33
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
about times x structname - this doesn't work, because structure must be preceded by label <url=http://www.decard.net/tajga.php?chapter=preproc#struc>.

Only solution i see for your problem is to overload all data definiton directives (db, dd, dq, rb, rw etc.) with structure to produce this constant (sizeof.data). They should be overloaded in struct macro, but then you would have to end definition with some "ends" or another macro, not only with "}", because overloaded directives must be purged there.

But I can't see reason for doing this, would it be worth of all that time loss?
Post 01 Jun 2004, 10:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Daemon



Joined: 08 Jul 2003
Posts: 15
Daemon
can i get an example of overloading db,dd,etc.. directives?
Post 02 Jun 2004, 10:36
View user's profile Send private message Reply with quote
zjlcc



Joined: 23 Jul 2003
Posts: 32
Location: china
zjlcc
you can:
Code:
struc db [data]
{
common
  local zzz
  label zzz
  db data
  .size=$-zzz
}
struc dd [data]
{
common
  local zzz1
  label zzz1
  dd data
  .size=$-zzz1
}
struc rb [data]
{
common
  local zzz2
  label zzz2
  rb data
  .size=$-zzz2
}
macro DB field,var
{
   field db var
   field#.#size=$-field
}  
macro DD field,var
{
   field dd var
   field#.#size=$-field
}  
macro RB field,var
{
   field rb var
   field#.#size=$-field
}  
struc S1 
{
  .data1 db ? 
  .data2 dd ? 
  .data3 rb 128 
} 
s1 S1 

struc S2 
{ 
  DB .data1,? 
  DD .data2,? 
  RB .data3,128 
} 
s2 S2
............
mov eax,s1.data1.size
mov ecx,s1.data2.size
mov ecx,s1.data3.size
nop
mov ecx,s2.data1.size
mov ecx,s2.data2.size
mov ecx,s2.data3.size
    
Post 02 Jun 2004, 13:29
View user's profile Send private message Reply with quote
Daemon



Joined: 08 Jul 2003
Posts: 15
Daemon
And what about
Code:
mov eax,s1.size     
???

i think sizeof directive must be added as a preprocessor directive; then we'll have every data size defined.

Greetz,
    Daemon
Post 08 Jun 2004, 03:30
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
surely not preprocessor directive, preprocessor does only string manipulation, nothing with directives (only it's own), size of data, expressions (5*sizeof.data) etc.

I don't like that idea, it would produce too much unneeded overhead. Why do you need to have size of dword variable defined (in assembly, where you must know if to put it into dword register)? And how many structure definitions you have, is it that problem to write sizeof. constant yourself for every "rb" in strucutre? Remember, trying to save *typing* usually isn't right solution.
Post 08 Jun 2004, 16:59
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.