1. 环境准备
下载汇编器fasm
,flat assembler 1.73.32 for Windows
配置环境变量:
- 将
fasm
安装路径添加至path
:D:\dev_tools\fasm\fasmw17332
- 设置
INCLUDE
变量:D:\dev_tools\fasm\fasmw17332\INCLUDE
2. 编写代码
创建hello.asm
。
format PE console
entry start
include 'win32a.inc'
;======================================
section '.data' data readable writeable
;======================================
hello_newline db "Hello World!",10,0
hello_no_newline db "Hello World! (without a new line)",0
;=======================================
section '.code' code readable executable
;=======================================
start:
ccall [printf],hello_newline ; Print 'Hello World!' and start a new line.
ccall [printf],hello_no_newline ; Print 'Hello World!' without starting a new line.
ccall [getchar] ; I added this line to exit the application AFTER the user pressed any key.
stdcall [ExitProcess],0 ; Exit the application
;====================================
section '.idata' import data readable
;====================================
library kernel,'kernel32.dll',\
msvcrt,'msvcrt.dll'
import kernel,\
ExitProcess,'ExitProcess'
import msvcrt,\
printf,'printf',\
getchar,'_fgetchar'
3. 代码运行
命令行窗口运行:
F:\code-work\code-test\fasm>fasm hello.asm
flat assembler version 1.73.32 (1048576 kilobytes memory)
3 passes, 0.1 seconds, 2048 bytes.
F:\code-work\code-test\fasm>hello.exe
Hello World!
Hello World! (without a new line)
fasm hello.asm
编译并链接生成可运行程序hello.exe
。
4. 参考
FASM: Hello World (Windows/Console)
标签:code,FASM,HelloWorld,hello,fasm,World,line,Hello From: https://www.cnblogs.com/yezhechenyang/p/18217654