Skip to content

SpeedyTurtle599/x64asm-experiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x64asm - x86-64-v3 Assembler

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.

Features

  • 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 .o files
  • 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

Architecture

┌─────────────┐
│   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
└─────────────┘

Building

make

This will produce the x64asm executable.

Usage

./x64asm input.s -o output.o

Then link with lld:

ld.lld output.o -o program

Supported Features

Directives

  • .text, .data, .bss - Section declarations
  • .globl - Export symbols
  • .align - Alignment directives
  • .byte, .word, .long, .quad - Data definitions
  • .ascii, .asciz, .string - String definitions

Instructions

  • 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

Operand Types

  • 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

File Format

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

Implementation Notes

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

License

Public Domain / MIT

Author

Built with assembly precision.

About

x86-64-v3 assembler from scratch. Generates ELF64 files for lld or comparable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published