flat assembler
Message board for the users of flat assembler.

Index > Windows > An example of SIZEOF

Author
Thread Post new topic Reply to topic
BoR0



Joined: 12 Nov 2004
Posts: 31
BoR0
I tried all, even googling.
I just cant sort it out. Crying or Very sad

Please give me some example of how to use it and all the needed include files.
Post 09 Feb 2005, 13:34
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis
mov eax,string
call getsize ; Get size of eax and overwrite it to eax

RET
getsize:
push esi
mov esi,0
@@:
inc esi
cmp byte[eax+esi],0
jne @B
mov eax,esi
pop esi
RET
Post 09 Feb 2005, 14:21
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
sizeof is declared by structure macros when you define a new structure:
Code:
struct my_structure
   field_1 dd ?
   field_2 rb 128
ends    

after this definition you can use sizeof.my_structure to obtain number of bytes that structure occupies.
Post 09 Feb 2005, 15:50
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
or this:

Code:
proc _strlen, string
  mov     edi,[string]
        cld
 xor     eax,eax
     or      ecx,-1
      repne   scasb
       not     ecx
 dec     ecx
        xchg    ecx,eax
      return
endp
    


eax - length of string
Post 09 Feb 2005, 15:54
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis
hmm vasilev v nice code :-s donno how to use not... :-s
Post 10 Feb 2005, 18:27
View user's profile Send private message Reply with quote
BoR0



Joined: 12 Nov 2004
Posts: 31
BoR0
decard, you got it right! that is my point!

Sorry guys, I already know of the string length algo, that was not my point though.

BTW, why does sizeof works for structures only?

I tried

Code:
section '.code' code readable executable
mov eax, sizeof.my_structure
invoke ExitProcess, 0

section '.data' data readable writeable
my_structure dd ?
    


and it didn't assemble Sad please reply!
Post 10 Feb 2005, 19:00
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
sizeof is defined by struct macro (it is a macro, not a built-in keyword; built-in is named "struc"). That's why it isn't defined by "dd" directive. You have just to remember that it has 4 bytes Wink maybe some macro expert could think of some solution Smile
Post 10 Feb 2005, 19:22
View user's profile Send private message Visit poster's website Reply with quote
BoR0



Joined: 12 Nov 2004
Posts: 31
BoR0
Well I personally think that it is a good idea to make SIZEOF work for all types of variables.. I mean, its an option that almost EVERY assembler supports it.

Thanks for all your help and kindness Smile
Post 10 Feb 2005, 21:15
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 GitHub, YouTube, Twitter.

Website powered by rwasa.