一个轻量级的 32 位 X86 汇编语言编译器,语法与 BASM 高度兼容。它能够生成极小体积的 Windows 可执行文件(.com 或 .exe),并支持实模式和保护模式下的代码编译。 通过修改指令集表(位于 XAsmTable.pas),还可以轻松扩展支持其他架构(如 ARM、RISC 等)。
特点:
支持生成极小体积的可执行文件(例如,Hello World 示例仅 444 字节)。
提供灵活的宏定义和结构体支持。
易于扩展,适合学习底层汇编语言和编译器开发。
独立运行:单文件编译器,无任何外部依赖(无需.NET/VC运行库)
编译20423行代码仅需 78 ms (AMD Ryzen3 3550h):
快速开始
使用编译器编译示例代码
./xasm HelloWorld.asm
运行生成的可执行文件
./HelloWorld.exe
示例代码:HelloWorld.asm
说明: 此示例展示了如何调用 Windows API (MessageBoxA) 显示一个消息框。编译后生成的 .exe 文件大小仅为 444 字节。
This example demonstrates how to call the Windows API (MessageBoxA) to display a message box. The compiled .exe file is only 444 bytes in size.
.FILEALIGN 4
.IMAGEBASE $400000
.IMPORT user32.dll,MessageBoxA
txt1&& DB 'Hello World!'
msgbox: MACRO handle=0,text=0,title=0,button=0
push &button
push &title
push &text
push &handle
call A[MessageBoxA]
END
Start:
msgbox handle=0,text=txt1,title=txt1,button=0
ret
复制代码
示例代码:API.asm
说明: 此示例展示了如何动态加载 DLL 并调用多个 API。编译后生成的 .exe 文件大小为 516 字节。
This example demonstrates how to dynamically load a DLL and call multiple APIs. The compiled .exe file is 516 bytes in size.
.FILEALIGN 4
//注意,不同的DLL必须单独使用 .IMPORT
//在定义后 API 名称将成为 Label
//用 CALL A[API名称] 的方式使用API
//本文件编译后 516 Bytes
.IMPORT kernel32.dll,GetProcAddress,LoadLibraryA
.IMPORT user32.dll,MessageBoxA
txt1&& DB 'Hello World!'
msgbox: MACRO handle=0,text=0,title=0,button=0
push &button
push &title
push &text
push &handle
call A[MessageBoxA]
END
Start:
msgbox handle=eax,text=txt1,title=txt1,button=0
ret
复制代码
示例代码:Option.asm
说明: 此示例展示了如何通过配置选项生成不同类型的可执行文件(如最小模式或 DLL)。
This example demonstrates how to generate different types of executable files (such as minimal mode or DLL) by configuring options.
.FILEALIGN 4 //文件对齐
.IMAGEBASE $400000 //影象文件基址
.TINYPE //最小模式编译
//.DLLMODE //编译为DLL
.SUBSYSTEM 2 //设置子系统, GUI == 2, CONSOLE == 3
Start:
.BUILDMSG 编译到这里时产生信息
ret
复制代码
示例代码:m-s.asm
说明: 此示例展示了如何定义结构体和宏,并在代码中使用它们。
This example demonstrates how to define structures and macros, and use them in the code.