FASM -- The almost perfect assembler

I once made a blog about how assembly is bloated so today I decided to try fasm, it was amazing, it's almost as efficient as C generated ELF,

For example, using NASM (or YASM but the difference is only 0.1 KB if not less) a Hello world program would look like this:


BITS 64

segment .text
global _start

_start:
    mov rax, 1
    mov rdi, 1
    mov rsi, m
    mov rdx, ml
    syscall

    mov rax, 60
    mov rdi, 0
    syscall

segment .rodata
m: db "Hello world!", 10
ml: equ $ - m

And when compiled using:

$ nasm -felf64 a.asm && ld -o a a.o

Where a.asm is the assembly source code you see above you get a 8.7 KB binary

So now let's do the same but using FASM:


format ELF64 executable 3
segment readable executable

_start:
    mov rax, 1
    mov rdi, 1
    mov rsi, m
    mov rdx, ml
    syscall

    mov rax, 60
    mov rdi, 0
    syscall

segment readable
m: db "Hello world!", 10
ml = $ - m

The code hasn't changed much but when we compile this code using:

$ fasm a.asm && chmod a+rx ./a

Where a.asm is the assembly source code you see above you get a 235 B binary

That's literally 8.465 KB improvement for only changing 5 lines of code... That's only one byte larger than out source code -- 234 B

Crazy how fast, small and nice this assembler is, give it a try! :)