Basically the same answer as cm, but uses a more generic set of macros.
%idefine TWORD_size 10
%idefine QWORD_size 8
%idefine DWORD_size 4
%idefine WORD_size 2
%idefine BYTE_size 1
%imacro VAR 2+
%{1}: %{2}
%{1}_size equ ($-%{1})
%endmacro
%idefine sizeof(_x_) _x_%+_size
;...
[SECTION .data]
var strMessage, DB "Hello World!", 0
var ptrMessage, DD strMessage
;...
[SECTION .bss]
var strBuffer, RESB 1024
;...
mov eax, sizeof(strMessage)
mov ebx, sizeof(ptrMessage)
mov ecx, sizeof(strBuffer)
mov edx, sizeof(dword)
I like this method and use it myself quite a lot, especially when dealing with the Linux system-call functions. For example:
[SECTION .data]
var strMessage, DB "Hello, World!"
;...
mov edx, sizeof(strMessage)
mov ecx, strMessage
mov ebx, FILENO_STDOUT
mov eax, SYS_write
int 0x80
Seems a bit more readable to me. In fact, I tend to add VAR and SIZEOF into the standard macros file so my personal build of NASM has these fixed in by default, just have to move the file over on each build.