TYPE: 獲取類型大小, 對數組是獲取每個元素的大小
; Test10_1.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data?
v1 db ?
v2 dw ?
v3 dd ?
v4 df ?
v5 dq ?
v6 dt ?
v7 db 1024 dup(?)
.code
main proc
PrintDec (type v1) ;1
PrintDec (type v2) ;2
PrintDec (type v3) ;4
PrintDec (type v4) ;6
PrintDec (type v5) ;8
PrintDec (type v6) ;10
PrintDec (type v7) ;1
ret
main endp
end main
$: 當前程序語句的地址
; Test10_2.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
V1 db 11,22,33,44
V1Size = ($ - V1) ;這是變量 V1 的大小
V2 dw 11,22,33,44
V2Size = $ - V2 ;這是變量 V2 的大小
V3 dd 10 dup(0)
V3Size = $ - V3 ;這是變量 V3 的大小
V3Len = ($-V3) / 4 ;這是變量 V3(dWord 類型數組)的元素數目
V4 db 'abcdefghijklmnopqrstuvwxyz', 0
V4Size = $ - V4 ;這是變量 V4 的大小
.code
main proc
PrintHex $ ;00401001, 這是當前語句的地址
PrintDec V1Size ;4
PrintDec V2Size ;8
PrintDec V3Size ;40
PrintDec V3Len ;10
PrintDec V4Size ;27
PrintHex $ ;0040135A, 這是當前語句的地址
ret
main endp
end main
LENGTHOF: 數組元素個數; SIZEOF: 總字節數
; Test10_3.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
v1 db 'abc', 0
v2 dd 11, 22, 33, 44, 55
v3 dd 10 dup(0)
.code
main proc
PrintDec (lengthof v1) ;4
PrintDec (lengthof v2) ;5
PrintDec (lengthof v3) ;10
PrintDec (sizeof v1) ;4
PrintDec (sizeof v2) ;20
PrintDec (sizeof v3) ;40
ret
main endp
end main
TYPEDEF: 創建自定義類型
; Test10_4.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
;自定義一個等同於 DWord 的類型: Cardinal
Cardinal typedef ptr dWord
.data
val Cardinal 100 ;使用 Cardinal 定義變量
.code
main proc
PrintDec val ;100
ret
main endp
end main
;TYPEDEF 還用於定義函數原型, 如:
;MyType typedef proto :DWORD, :DWORD, :DWord