flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > .sizeof for local variable arrays?

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Has anyone written or can write a way to define a sizeof. value for local variable arrays? an example of what I'm looking for is below.

proc MyFunction
local arrayofdwords[512]:DWORD, arrayofchar[256]:BYTE,
arrayofdouble[32]:QWORD

mov eax, sizeof.arrayofdwords ;set to 2048 bytes
mov eax, sizeof.arrayofchar ;set to 256 bytes
mov eax, sizeof.arrayofdouble ;set to 8*32 (256 bytes)
endp

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 02 Sep 2008, 14:51
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
qood idea for Tomasz, IMHO
Post 02 Sep 2008, 19:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
The way Tomasz has the macros for the proc related things makes it a little tricky to properly make the sizeof.var truly act like a local label. It would be easy to make a normal global label with just a few simple changes.

Someone with a little time to spare may like to go through the whole proc macro code and do the necessary changes. I'm sure they would also learn much about how these macros work in the process.
Post 03 Sep 2008, 02:20
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
Hallo all,
i have tried to add the following line

sizeof.\#varname = $ - varname
to the "local" macro in PROC32.inc
after the line ~247
...
...
line 243...
match , done@local \\{ virtual
varname vartype
end virtual
rb count*sizeof.\#vartype
restore done@local \\}
sizeof.\#varname = $ - varname ;<--so,add this line

\}
...
...
And it works good !!! Very Happy
(locals/endl are not affected by this modification)
But i am afraid this is not the right way to do it.Confused
..
hopcode
Post 03 Sep 2008, 23:40
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: 17270
Location: In your JS exploiting you and your system
revolution
Yes, that it a global label, that was the easy part I mentioned. Just be aware of it if you get a duplicate label error when assembling.

If you want a genuine local label then you will need another solution.
Post 04 Sep 2008, 00:59
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
Hallo all,
Here a solution Very Happy Very Happy applied only to the datatype

local name[xxx]:BYTE

It could be easily extended to any type.
It is also interesting the fact that this
mechanism is similiar to the mechanism in PROC302.inc.

So it could be easily integrated in PROC32.inc,
without the need of wrapping with the _x
macro. It is to say, direct in the well kwnown
proc/local/endp etc. macro.

I have had no time to do it. But first I wanted submit to you
this idea, in order to have from it a feedback.
FASM FASM FASM
Code:
format PE CONSOLE 4.0
entry start

      include '%fasminc%\win32a.inc'
   section ".data" data readable writeable
           dd 0
        section ".code" code readable executable

macro _x arg
{
 match =proc rest,arg
 \{
 all@sizes equ
  \\proc rest
 \}

 match =local rest,arg
 \{
 match varname[count]:vartype, rest
  \\{
   match =BYTE, vartype 
  \\\{
        ;display_decimal count
      ;display \\\`varname
     match vars, all@sizes \\\\{ all@sizes equ all@sizes, \\\\}
        all@sizes equ all@sizes varname\\#.size
   varname\\#.size equ count
   \\\}
  \\}
  \\local rest
 \}

  match =endp,arg
  \{
   \\endp
    match vars,all@sizes
    \\{
     restore vars 
    \\}
    restore all@sizes
  \}
}

    start:
          call p1
             nop
         nop

     ;       display_decimal alfa.size       ;decommenting gives error
   ;       display_decimal beta.size       ;decommenting gives error

       _x proc p1
          _x local alfa[256]:BYTE
         _x local beta[100]:BYTE
                 lea eax,[alfa]
                      mov eax,alfa.size
                   ; display_decimal alfa.size ;OK, known label
                        ; display_decimal beta.size     ;OK, known label
            ret
 _x endp

;        display_decimal alfa.size       ;decommenting gives error
;  display_decimal beta.size       ;decommenting gives error
    


hopcode[mrk]
Post 05 Sep 2008, 10:08
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Thanks hopcode, your stuff looks good Smile . I'll see if I can take this further, and find a truly transparent solution.
Post 05 Sep 2008, 12:46
View user's profile Send private message Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
Hallo all,
/to madmatt/ thanks Very Happy. Try this PROC32.INC attached.
It allows varname.size on all types of local.
I have but tested it not extensively.It should be complete
for all all the types. Less than 10 lines in addition to
the Priva-code. Very Happy
..
FASM FASM FASM
hopcode[mrk]

_________________
⠓⠕⠏⠉⠕⠙⠑


Last edited by hopcode on 05 Apr 2011, 16:38; edited 1 time in total
Post 05 Sep 2008, 15:12
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hey, thanks hopcode, I'll give it a try sometime today or tommorrow.
Post 06 Sep 2008, 10:42
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Thanks a bunch hopcode, I've tried it and it works good, but one small change and a small problem. I made a change to the code so the variable will be just like a struct sizeof.xxx variable (see below). also, DQWORD doesn't work right, I'll see if I can find what the problem is.

Code:
   ;--------------------X--lines by hopcode
   ;---------------------------
   ;display_decimal $-..var
   ;display `name
   ;-----------------------
                match vars, all@sizes \{ all@sizes equ all@sizes, \}
                all@sizes equ all@sizes name#.size
                ..var#.size = $ - ..var
                sizeof.#name equ ..var#.size ;CHANGED: name#.size equ ..var#.size
        ;--------------------X--lines by hopcode
    
Post 06 Sep 2008, 13:34
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.

Powered by rwasa.