News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Finding the length of a variable, I think.

Started by Troy Lundin, June 05, 2006, 07:28:47 AM

Previous topic - Next topic

Troy Lundin

Say I have the following:

var1 db 01h,02h,03h,04h

Is there a way to tell how many values I have in var1 (4 values)?

ChrisLeslie

Hi Troy

This is quoted from the MASM reference:
QuoteThe LENGTHOF operator returns the number of data items allocated
     for <variable>. The SIZEOF operator returns the total number of
     bytes allocated for <variable> or the size of <type> in bytes. For
     variables, SIZEOF is equal to the value of LENGTHOF times the
     number of bytes in each element.

Therefore "lengthof var1" will return a value of 4

Chris

Mark Jones

Quote
var1 db 01h,02h,03h,04h

Is there a way to tell how many values I have in var1 (4 values)?

Also note that "var1" and variables in general do not work the same in assembler as in other languages - there is really no such thing as a variable in assembler, only data and offsets. See \masm32\help\asmintro.hlp for a complete explanation.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08