offset 偽指令的使用
;偽指令 類似與高級語言
; offset 偏移量 距離段啟始位置的偏移地址,獲取的始一個地址
1.數組的第一種使用
//省略了頭 .data arrNum dword 0,1,2,3 .code main proc mov eax,[arrNum+4] call ExitProcess add esp,4 main ENDP END main
2.用offset 對地址操作
重要知識點:
;把arrNum 偏移地址移到eax
mov eax,offset arrNum + 4 ;因為eax里面保存的是地址,所以用 [] 是取地址的值 mov eax,[eax]
.586 .MODEL flat,stdcall option casemap:none ; inc 是一個頭文件 include windows.inc include user32.inc include kernel32.inc ;msvcrt.inc 引用c中的輸入輸出功能 include msvcrt.inc ;庫文件 includelib user32.lib includelib kernel32.lib includelib msvcrt.lib .data arrNum dword 0,1,2,3 .code main proc ;把arrNum 偏移地址移到eax mov eax,offset arrNum + 4 ;因為eax里面保存的是地址,所以用 [] 是取地址的值 mov eax,[eax] call ExitProcess add esp,4 main ENDP END main
ptr 偽指令的使用
;使用: word ptr 操作數 //取操作數的低16位,word 可以換位其他數據類型
;eax 是32位的 ax是16位,eax的低16位
.data ;arrNum word 0,1,2,3 arrNum dword 5 .code main proc ;把arrNum 偏移地址移到eax mov ax,word ptr arrNum call ExitProcess add esp,4 main ENDP END main ;偽指令 類似與高級語言 ; ptr ;使用: word ptr 操作數 //取操作數的低16位 ;eax 是32位的 ax是16位,eax的低16位
lengthof、sizeof 偽指令的使用
lengthof 計算數組返回多少元素
lengthof使用:
mov eax,offset lengthof arrNum
sizeof 字節數*數組的個數
sizeof的使用:
mov eax,sizeof arrNum
.586 .MODEL flat,stdcall option casemap:none ; inc 是一個頭文件 include windows.inc include user32.inc include kernel32.inc ;msvcrt.inc 引用c中的輸入輸出功能 include msvcrt.inc ;庫文件 includelib user32.lib includelib kernel32.lib includelib msvcrt.lib .data ;arrNum word 0,1,2,3 arrNum db 0,1,2,3 .code main proc mov eax,offset lengthof arrNum call ExitProcess add esp,4 main ENDP END main ;偽指令 類似與高級語言 ; type ;使用: word ptr 操作數 //獲得數據的類型的字節數 ;lengthof 計算數據返回多少元素