FASM之HelloWorld
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 ; 0代表字符串结束。10代表换行符,ASCII码表可查。
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
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述