flat assembler
Message board for the users of flat assembler.

Index > Main > sizeof

Author
Thread Post new topic Reply to topic
killasmurf86



Joined: 29 Sep 2010
Posts: 36
killasmurf86
I suppose there is nothing that can be something similar to sizeof function...
in fasm this could be used to get size in bytes of data, or structure....
Yes, I know about $-some_date method, but in some cases it won't work....

sizeof macro could be useful, for other macros
For example
Code:
sizeof(eax) => 4

some_data dw 10
sizeof(some_data) => 2

sizeof(name of structure) could return size of structure :D
    


This could be relatively simple to implement, since fasm remembers size of declared data

Well at least right now this would be very useful for me as I'm porting few marcos from C to fasm (I need this for University)


The problem is, that if I create generic Include file that would be used by others, I can't expect to have data_size = $-data for every single variable/structure in app

also sizeof(register), while it's a common knowledge, it could allow programmer to write quite powerful macros (I think)

Good/bad idea? What do you think....
Post 31 Oct 2010, 12:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
Code:
struc dw [arg] {
 common
 . dw arg
 sizeof.#. = $-.
}
sizeof.eax = 4

some_data1 dw 10
some_data2 dw 10,20,30,40
display sizeof.some_data1+'0',',',sizeof.some_data2+'0'    
Post 31 Oct 2010, 13:47
View user's profile Send private message Visit poster's website Reply with quote
killasmurf86



Joined: 29 Sep 2010
Posts: 36
killasmurf86
revolution wrote:
Code:
struc dw [arg] {
 common
 . dw arg
 sizeof.#. = $-.
}
sizeof.eax = 4

some_data1 dw 10
some_data2 dw 10,20,30,40
display sizeof.some_data1+'0',',',sizeof.some_data2+'0'    


Very, very impressive cheat
Thanks
Post 31 Oct 2010, 14:42
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
killasmurf86,

There is a generic one:
Code:
struc sized [args] {
common . args
sizeof.#. = $ - .
}    
Usage is simple:
Code:
prompt sized db "Enter something: "
prefix sized db "You've entered: "
input sized rb 100    
This code gets sizeof.prompt, sizeof.prefix and sizeof.input properly defined. I call that kind of macro prefix-macro.
Post 31 Oct 2010, 16:13
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.