The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Troy Lundin on June 05, 2006, 07:28:47 AM

Title: Finding the length of a variable, I think.
Post by: Troy Lundin on June 05, 2006, 07:28:47 AM
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)?
Title: Re: Finding the length of a variable, I think.
Post by: ChrisLeslie on June 05, 2006, 07:59:50 AM
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
Title: Re: Finding the length of a variable, I think.
Post by: Mark Jones on June 07, 2006, 02:59:12 AM
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.