Code formatter for NASM x86 assembly code
  • Rust 85.1%
  • Assembly 14.9%
Find a file
2026-05-10 22:22:50 +01:00
.github/workflows feat(ci): Lint, build, and test in CI 2026-05-08 14:29:29 +01:00
docs feat: Add code coverage badge to README 2026-05-08 19:37:06 +01:00
src feat(deps): Decrease required Rust version to 1.88 2026-05-09 00:00:18 +01:00
tests feat(deps): Decrease required Rust version to 1.88 2026-05-09 00:00:18 +01:00
.gitignore feat: Initial commit 2026-05-07 23:58:49 +01:00
Cargo.lock feat(deps): Decrease required Rust version to 1.88 2026-05-09 00:00:18 +01:00
Cargo.toml feat(deps): Decrease required Rust version to 1.88 2026-05-09 00:00:18 +01:00
LICENCE chore: Update licence 2026-05-08 14:21:44 +01:00
README.md chore: Add Crates.io link to README 2026-05-10 22:22:50 +01:00

nasfmt

Crates.io Version Coverage

Code formatter for NASM x86-64 assembly.

Install

$ cargo install nasfmt

Usage

Format a file in place:

$ nasfmt file.s

Format multiple files in place:

$ nasfmt file1.s file2.s file3.s

Check formatting without modifying files (exits 1 with a diff if changes are needed):

$ nasfmt --check tests/resources/main.s
--- tests/resources/main.s
+++ tests/resources/main.s
@@ -103,9 +103,9 @@
     syscall
     cmp     rax, 0
     jle     no_input_connected
-    movzx   rax, byte [input_char] ; Convert ASCII to integer
-    sub   rax, '0'
-    cmp      rax, 1                    ; Check lower bound
+    movzx   rax, byte [input_char]    ; Convert ASCII to integer
+    sub     rax, '0'
+    cmp     rax, 1                    ; Check lower bound
     jl      invalid_input
     cmp     rax, 9                    ; Check upper bound
     jg      invalid_input

What it does

  • Normalises mnemonics, registers, and size prefixes to lowercase (MOV RAXmov rax), or uppercase if the --upper flag is passed
  • Aligns operands and comments consistently within each instruction block
  • Ensures labels appear on their own line
  • Standardises spacing inside memory operands ([rbp-8][rbp - 8])
  • Leaves user-defined symbol names and string literals untouched

Reference