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 @ 2024-05-28 12:02  叶遮沉阳  阅读(53)  评论(0编辑  收藏  举报