在使用数组时通常会想要知道它的大小:
list byte 10, 20, 30, 40
listsize = 4 ;显式声明数组大小容易导致错误,比如后续又插入或删除元素时。最好办法是让编译器计算。
$运算符返回当前程序语句的偏移量,上面的代码可以改为:
list byte 10, 20, 30, 40
listsize = ($ - list) ;list必须紧跟在数据声明的后面。
不要手动计算字符串的长度,让编译器完成:
mystring byte "this is a long string, containing"
byte "any number of characters"
mystring_len = ($ - mystring)
计算一个数组的元素数量:
list word 1000h, 2000h, 3000h, 4000h
listsize = ($ - list) / 2 ;一个word占2字节,除以2可以得出有多少个word
list dword 10000000h, 10000000h, 10000000h, 10000000h
listsize = ($ - list) /4 ;一个dword占4字节,除以4可得有多少个dword。