在MASM中获取结构尺寸 [英] Get structure size within MASM
问题描述
我想知道如何在MASM编译时获取结构的大小.
I am wondering how to get the size of a structure at compilation time in MASM.
这是C的等效代码.
struct Point
{
int x;
int y;
};
printf("Point Stucture size %d\n", sizeof(struct Point));
推荐答案
我假设您将在汇编代码中声明该结构.
根据masm32文档,您可以使用以下运算符给你:
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
说明
LENGTHOF
运算符返回分配给<variable>
的数据项的数量. SIZEOF
运算符返回分配给<variable>
的字节总数或<type>
的大小(以字节为单位).对于变量,SIZEOF
等于LENGTHOF
的值乘以每个元素中的字节数.
The 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.
允许LENGTH
和SIZE
运算符与以前版本的汇编程序兼容.当应用于数据标签时,LENGTH
运算符将返回由DUP
运算符创建的元素数.否则返回1.应用于数据标签时,SIZE
运算符将返回第一个初始化程序在<variable>
标签处分配的字节数.
The LENGTH
and SIZE
operators are allowed for compatibility with previous versions of the assembler. When applied to a data label, the LENGTH
operator returns the number of elements created by the DUP
operator; otherwise it returns 1. When applied to a data label, the SIZE
operator returns the number of bytes allocated by the first initializer at the <variable>
label.
MASM 6.1中的LENGTHOF
和SIZEOF
运算符更一致地处理数组.这些运算符返回初始化项中的数据项数和字节数.
The LENGTHOF
and SIZEOF
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.
请参阅masm32/help目录中的masm32.chm.
See masm32.chm in the masm32/help directory.
这篇关于在MASM中获取结构尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!