A complete x86-64 assembler written in x64 assembly language. This assembler can process .s assembly files and generate ELF64 object files compatible with LLVM's lld linker.
- Pure x64 Assembly Implementation: All modules written in x86-64 assembly
- x86-64-v3 Support: Supports the x86-64-v3 microarchitecture level
- ELF64 Object Output: Generates standard ELF64
.ofiles - LLVM lld Compatible: Output can be linked with LLVM's lld linker
- Linux Syscalls: Uses Linux kernel syscalls for I/O operations
- Modular Design: Separate lexer, parser, encoder, and ELF writer modules
┌─────────────┐
│ main.s │ - Entry point, command-line handling
└──────┬──────┘
│
v
┌─────────────┐
│ lexer.s │ - Tokenizes assembly source
└──────┬──────┘
│
v
┌─────────────┐
│ parser.s │ - Parses tokens into instructions/directives
└──────┬──────┘
│
v
┌─────────────┐
│ encoder.s │ - Encodes instructions to machine code
└──────┬──────┘
│
v
┌─────────────┐
│ elfgen.s │ - Generates ELF64 object files
└─────────────┘
makeThis will produce the x64asm executable.
./x64asm input.s -o output.oThen link with lld:
ld.lld output.o -o program.text,.data,.bss- Section declarations.globl- Export symbols.align- Alignment directives.byte,.word,.long,.quad- Data definitions.ascii,.asciz,.string- String definitions
- Basic arithmetic:
add,sub,mul,imul,div,idiv - Logical:
and,or,xor,not,neg - Shifts:
shl,shr,sal,sar,rol,ror - Data movement:
mov,lea,push,pop - Control flow:
jmp,je,jne,jg,jl, etc.,call,ret - System:
syscall,nop - x86-64-v3 specific: SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2 instructions
- Registers:
rax,rbx,rcx, etc. (64-bit),eax,ebx, etc. (32-bit) - Immediates:
$123,$0x1a,$-5 - Memory:
(%rax),8(%rsp),symbol(%rip),(%rax,%rbx,4) - Labels:
my_label:and references
The assembler generates ELF64 object files with:
- Proper section headers (.text, .data, .bss, .symtab, .strtab, .shstrtab)
- Symbol table with local and global symbols
- Relocation entries for external references
- Compliant with System V ABI
All code is written in x86-64 assembly with:
- Clear prologues/epilogues: All functions follow standard calling conventions
- Stack frame management: Proper
rbp-based stack frames - Linux syscalls: Direct syscall interface for I/O
- Position-independent: Can be assembled at any address
Public Domain / MIT
Built with assembly precision.