I am wondering how to get the size of a structure at compilation time in MASM.
Here is the C equivalent code.
struct Point
{
int x;
int y;
};
printf("Point Stucture size %d\n", sizeof(struct Point));
I'm assuming that you'll be declaring the struct in your assembly code.
According to the masm32 documentation you've got the following operators available to you:
LENGTHOF variable
SIZEOF variable
SIZEOF type
LENGTH expression
SIZE expression
Description
The
LENGTHOF
operator returns the number of data items allocated for<variable>
. TheSIZEOF
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 ofLENGTHOF
times the number of bytes in each element.The
LENGTH
andSIZE
operators are allowed for compatibility with previous versions of the assembler. When applied to a data label, theLENGTH
operator returns the number of elements created by theDUP
operator; otherwise it returns 1. When applied to a data label, theSIZE
operator returns the number of bytes allocated by the first initializer at the<variable>
label.The
LENGTHOF
andSIZEOF
operators in MASM 6.1 handle arrays much more consistently. These operators return the number of data items and the number of bytes in an initializer.
See masm32.chm in the masm32/help directory.