本文介绍利用RedASM写一个messageBox “hello world”.
RadAsm 是我用过最爽的一个汇编IDE了, 代码高亮,智能提示……
RadASM支持多种不同的汇编编译器,这里我们选择MASM.既然是IDE了,创建工程就很简单了, 文件->Win32 App(no res)->名字“MessageBox,”一路Next.
然后呢,我们写下如下的汇编程序:
Title: Hello world ;Author: sld6666666@gmail.com ;Data: 2010-11-05 ;Description: Assemble hello world .386 ;该程序对CPU的最低要求是intel 386 .model flat, stdcall ; 平坦内存模型, stacll 函数调用方式 .stack 4096 ;栈的大小为4096B option casemap:none ;include 头文件, 连接库 include windows.inc include kernel32.inc include user32.inc includelib kernel32.lib includelib user32.lib .data ;数据段 sztitle db "hello",0 ;0 很重要, 因为是0结尾 szText db "Hello world",0 .code ;这里是代码区域 main proc ;proce 表示程序的开始 invoke MessageBox,NULL, offset szText, ;invoke 关键字表明这个是从其他库导入的 offset sztitle, MB_OK invoke ExitProcess,NULL ret ;程序返回 main endp ;endp表示proc过程的结束 end main ;end 表明该行是汇编程序的最后一行
就OK了。
这里附上效果图,供大家参观:
这里再补一个hello world 的控制台程序
.386 ;该程序对CPU的最低要求是intel 386
.model flat, stdcall ; 平坦内存模型, stacll 函数调用方式
.stack 4096 ;栈的大小为4096B
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
.data
inchar DB ?
numwritten DD ?
numread DD ?
outhandle DD ?
inhandle DD ?
strHello DB "Hello World!"
.code
main proc
invoke AllocConsole
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [outhandle],eax
invoke GetStdHandle,STD_INPUT_HANDLE
mov [inhandle],eax
invoke WriteConsole,[outhandle], offset strHello,12,numwritten,0
invoke ReadConsole,[inhandle],inchar,1,numread,0
invoke ExitProcess,0
main endp
end main
来一个更简单的:
.386
.model flat, stdcall
option casemap :none
include windows.inc
include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.data
helloWorld db "hello world",0
.code
start:
invoke StdOut, addr helloWorld
invoke ExitProcess,0
end start
http://www.cnblogs.com/sld666666/archive/2010/11/14/1877260.html