把数据写到代码段
2008-10-14 09:35:12 来源:WEB开发网看下面的小程序,很简单,你认为执行结果会是什么?
------------------------------------------------------------
;文件名:11.ASM
;利用console显示一个字符串信息
.386
.model flat,stdcall
option casemap:none
include \MASM7\INCLUDE\windows.inc
include \MASM7\INCLUDE\kernel32.inc
include \MASM7\INCLUDE\masm32.inc
includelib \MASM7\LIB\kernel32.lib
includelib \MASM7\LIB\masm32.lib
.code
messAdd dd 0
mess db 'How are you !',0
start:
lea eax,mess
mov messAdd,eax ;写代码段中的数据
invoke StdOut,messAdd
invoke ExitProcess,NULL
end start
-----------------------------------------------------------
太简单啦,不就是利用console输出一个字符串?对啦,这就是程序的原意!
但结果却不是想象的。因为在执行程序时,映入我们眼帘的首先是一个错误的消息框!
为什么会这样呢?因为Windows在链接时设置代码段一个属性,那就是“读\执行\代码”,就是不允许写。所以就出错啦!有没有解决的办法呢?
照着下面的操作吧,它可使代码段有写的属性:
D:\MASM7>ml /coff 4.asm /link /subsystem:console /section:.text,rw ;R-读,W-写
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: 4.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/subsystem:console /section:.text,rw
"4.obj"
"/OUT:4.exe"
D:\MASM7>11
How are you !
D:\MASM7>_
更多精彩
赞助商链接