Let;s say I declare

arr db 1,2,3

How do I know arr's size afterwards? is there a command for it?
I know there is something about arr-$ or something that I can declare in the ds segment but I think it works for strings only...

Edited by UtaChan: n/a

7 Years
Discussion Span
Last Post by UtaChan

That means, if I get an array I dunno its size (not stored in any variable and nothing to end it like null or $ or anything stated) I can;t find the size?
(In the code segment,like a command, like in C# there is 'sizeof').

I mean let's say I have something that is dup 100 (?), and I fill it in, like getting some numbers from the keyboard, does it mean I can;t know how many numbers I got by the vector itself? (let;s say I chose not to use a counter to count the times the user inserted another number..


Yes, in MASM you can use the sizeof operator:

mov		eax, SIZEOF arr

OR after you define arr, you can get the size using the $ char (I forgot what it is called)

arr db 1,2,3
ARR_SIZE		equ	$ - arr

	mov		eax, ARR_SIZE

Wich is more versatile than the sizeof operator. You cannot use the sizeof operator on an array of DWORDS because it will return 4 no matter how many elements you have... so you would use the $ after the array like so:

sz1				BYTE	"Hello", 0
sz2				BYTE	"There", 0
sz3				BYTE	"My Friend!", 0

SomeArray		DWORD	offset sz1
				DWORD	offset sz2
				DWORD	offset sz3
SOMEARRAY_SIZE	equ	($ - SomeArray) / SIZEOF DWORD ; or use 4

Now, no matter how big your dword array is, it will give you the number of items..

Comes in handy when you are looping to load a combobox with strings or something :-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.