| 网站首页 | 文章中心 | 电子书下载 | 矢量图库 | 视频教程 | 素材下载 | 程序代码下载 | JS代码 | 论坛 | 
常用软件类:
|杀毒安全 |联络聊天 |网络软件 |多媒体类 |系统工具 |图形图像 |系统工具 |应用软件 |行业软件
开发设计类:
|动画制作 |图像处理 |3D设计 |操作系统 |站长学院 |网络相关 |WEB设计 |数据库类 |程序开发
汇编技巧Windows下控制台输出
作者:佚名    文章来源:网络    点击数:    更新时间:2006-12-9
 



;下面我们看一个程序,作用是显示一个字符串信息!

        .386
        .model flat,stdcall
        option casemap:none

include windows.inc

include kernel32.in

include user32.inc

includelib kernel32.lib
includelib user32.lib

        .data
mess    db ’How are you !’,0    ;要显示的信息

        .data?
StdOut  dd ?    ;存放标准输出的把柄
CharOut dd ?    ;记录实际输出的字符数

        .code
start:  
        invoke GetStdHandle,STD_OUTPUT_HANDLE   ;获取标准输出的把柄
        mov StdOut,eax      ;保存把柄号

        lea eax,mess
        invoke lstrlen,eax  ;求字符串的长度

        lea ecx,CharOut
        invoke WriteFile,StdOut,addr mess,eax,ecx,NULL  ;写文件
        
        invoke ExitProcess,NULL   ;程序结束
        end start
--------------------------------------------------------------
编译链接,下面给出详尽的信息,供分析参考:
D:\MASM7>dir /ad

Volume in drive D has no label
Volume Serial Number is 18F0-186B
Directory of D:\MASM7

.              〈DIR〉        02-12-03  17:36 .
..             〈DIR〉        02-12-03  17:36 ..
LIB            〈DIR〉       02-12-03  17:38 LIB
INCLUDE        〈DIR〉        02-12-03  17:38 INCLUDE
         0 file(s)              0 bytes
         4 dir(s)   2,411,925,504 bytes free

D:\MASM7>ml /coff /I include 4.asm /link /subsystem:console /libpath:lib
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 /libpath:lib
"4.obj"
"/OUT:4.exe"

D:\MASM7>4
How are you !
D:\MASM7>
--------------------------------------------------------------
另外,在masm32.inc中有函数StdOut的声明,可用来直接输出信息,把上面的例子修改后就是下面的样子,可见来得更简炼,供大家参考:

        .386
        .model flat,stdcall
        option casemap:none   ;case sensitive

include windows.inc

include kernel32.inc
include masm32.inc

includelib kernel32.lib
includelib masm32.lib

        .data
mess    db ’How are you !’,0    
     .code
start:  
        invoke StdOut,addr mess
        invoke ExitProcess,NULL
        end start

上一页  [1] [2] 


相关文章