ASM的一些小坑

变量必需放到数据段,才有直接对地址赋值的访问权限

segment .data
n1 dw 55h

segment .text

global _nasm_function

_nasm_function:
	mov eax, n1
	mov [eax], eax
	mov dword[n1], 05678h
	ret

此例变量n1如果不放在data段,那么

mov [eax], eax

这句将出现Access Violation内存访问失败错误

x64下

segment .data
n1 dq 55h

segment .text

global _nasm_function

_nasm_function:
	mov rax, n1
	mov [rax], rax
	;mov qword[n1], 05678h		;x64不能直接对qword ptr赋值

	ret

无法直接对qword ptr地址赋值,只能先把地址存入寄存器,再赋值

google参考了这个页面

https://www.experts-exchange.com/questions/27250951/LNK2017-error-with-MASM64.html

原文地址:https://www.cnblogs.com/kileyi/p/7396267.html