FASM之HelloWorld

1. 环境准备

下载汇编器fasmflat assembler 1.73.32 for Windows

配置环境变量:

  • fasm安装路径添加至pathD:\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

4. 参考

notepad++ 配置fasm汇编环境

FASM: Hello World (Windows/Console)

posted @   叶遮沉阳  阅读(133)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示