AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > 汇编语言

把数据写到代码段

51自学网 http://www.51zixue.net
   看下面的小程序,很简单,你认为执行结果会是什么?
------------------------------------------------------------
;文件名: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>_

 

 

 
上一篇:修改文件操作  下一篇:PE文件结构剖析