v1.0.0

TigerASM

High-Performance Runtime Assembler for Python

JIT Compilation • x86_64 & ARM64 • Virtual Memory

Features

JIT Compilation

Runtime assembly compilation and execution with native performance. Write assembly code and execute it instantly.

🎯

Multi-Architecture

Full support for both x86_64 and aarch64 (ARM64) architectures with automatic detection.

💾

Virtual Memory

10MB simulated memory space for data manipulation with full read/write capabilities.

🔧

Register Control

Complete register state management for both x86_64 and ARM64 architectures.

📁

File Operations

Load and save binary files directly to/from memory with seamless integration.

🚀

Python Native

Built with Rust and PyO3 for maximum performance while maintaining Python simplicity.

Quick Start

Installation
# Install via pip
pip install tigerasm

# Or build from source
git clone https://github.com/yourusername/tigerasm
cd tigerasm
pip install maturin
maturin develop --release
Basic Example
from tigerasm import TigerASM

# Create assembler instance
asm = TigerASM()
asm.setup("x86_64")

# Write assembly code
asm.asm("""
    mov rax, 42
    add rax, 8
    ret
""")

# Execute and get result
asm.execute()
print(f"Result: {asm.get('rax')}")

Examples

01

Simple Calculator

Calculate (10 + 20) × 3 using assembly instructions

calculator.py
from tigerasm import TigerASM

asm = TigerASM()
asm.setup("x86_64")

# Calculate (10 + 20) * 3
asm.asm("""
    mov rax, 10
    add rax, 20
    mov rbx, 3
    imul rax, rbx
    ret
""")

asm.execute()
print(f"Result: {asm.get('rax')}")
# Output: Result: 90
Output:
Result: 90
02

Loop with Labels

Sum numbers from 1 to 10 using a loop structure

sum_loop.py
asm = TigerASM()
asm.setup("x86_64")

# Sum numbers 1 to 10
asm.asm("""
    mov rax, 0      ; sum accumulator
    mov rcx, 1      ; counter
    
loop_start:
    add rax, rcx    ; add counter to sum
    inc rcx         ; increment counter
    cmp rcx, 11     ; compare with 11
    jl loop_start   ; jump if less than
    
    ret
""")

asm.execute()
print(f"Sum 1-10: {asm.get('rax')}")
Output:
Sum 1-10: 55
03

Memory Operations

Read and manipulate data stored in virtual memory

memory_ops.py
asm = TigerASM()
asm.setup("x86_64")

# Write data to memory
asm.write_mem(0x1000, 42, 8)
asm.write_mem(0x1008, 58, 8)

# Set base address register
asm.mov("rax", 0x1000)

# Read and sum values from memory
asm.asm("""
    mov rbx, [rax]      ; Load first value
    mov rcx, [rax + 8]  ; Load second value
    add rbx, rcx        ; Sum them
    mov rax, rbx        ; Return in rax
    ret
""")

asm.execute()
print(f"Sum: {asm.get('rax')}")
Output:
Sum: 100
04

String Length Calculator

Calculate the length of a null-terminated string in memory

string_length.py
asm = TigerASM()
asm.setup("x86_64")

# Write string to memory
text = b"Hello, TigerASM!\x00"
asm.write_bytes(0x2000, text)

# Count string length
asm.asm("""
    mov rsi, 0x2000     ; String address
    xor rax, rax        ; Length counter
    
count_loop:
    mov bl, [rsi + rax] ; Load byte
    test bl, bl         ; Check if zero
    jz done             ; Exit if zero
    inc rax             ; Increment counter
    jmp count_loop
    
done:
    ret
""")

asm.execute()
print(f"String length: {asm.get('rax')}")
Output:
String length: 16
05

Bitwise Operations

Perform bit manipulation and shift operations

bitwise.py
asm = TigerASM()
asm.setup("x86_64")

asm.asm("""
    mov rax, 0b11110000
    mov rbx, 0b10101010
    
    and rax, rbx        ; AND operation
    or rax, 0b00001111  ; OR with mask
    
    mov rax, 1
    shl rax, 4          ; Shift left by 4 (multiply by 16)
    
    ret
""")

asm.execute()
print(f"Result: {asm.get('rax')}")
print(f"Binary: {bin(asm.get('rax'))}")
Output:
Result: 16
Binary: 0b10000
06

Binary File Checksum

Load a binary file and calculate its checksum

checksum.py
asm = TigerASM()
asm.setup("x86_64")

# Load binary data
bytes_loaded = asm.load_binary_file("input.bin", 0x10000)

# Calculate checksum
asm.asm(f"""
    mov rsi, 0x10000         ; Data address
    mov rcx, {bytes_loaded}  ; Byte count
    xor rax, rax             ; Checksum accumulator
    
checksum_loop:
    test rcx, rcx
    jz checksum_done
    mov bl, [rsi]            ; Load byte
    add rax, rbx             ; Add to checksum
    inc rsi
    dec rcx
    jmp checksum_loop
    
checksum_done:
    ret
""")

asm.execute()
checksum = asm.get('rax')
print(f"Checksum: {checksum:#x}")
Output:
Checksum: 0x2a4f
07

Fibonacci Sequence

Calculate the nth Fibonacci number using recursion

fibonacci.py
asm = TigerASM()
asm.setup("x86_64")

# Calculate 10th Fibonacci number iteratively
asm.asm("""
    mov rcx, 10         ; n = 10
    mov rax, 0          ; fib(0)
    mov rbx, 1          ; fib(1)
    
    cmp rcx, 0
    je done
    
fib_loop:
    dec rcx
    cmp rcx, 0
    je done
    
    mov rdx, rax        ; temp = fib(n-2)
    mov rax, rbx        ; fib(n-2) = fib(n-1)
    add rbx, rdx        ; fib(n-1) = fib(n-1) + fib(n-2)
    jmp fib_loop
    
done:
    mov rax, rbx
    ret
""")

asm.execute()
print(f"Fibonacci(10): {asm.get('rax')}")
Output:
Fibonacci(10): 55
08

Array Maximum Finder

Find the maximum value in an array stored in memory

array_max.py
asm = TigerASM()
asm.setup("x86_64")

# Create array in memory
array = [5, 12, 7, 23, 9, 15, 3, 18]
for i, val in enumerate(array):
    asm.write_mem(0x3000 + i * 8, val, 8)

# Find maximum value
asm.asm(f"""
    mov rsi, 0x3000          ; Array address
    mov rcx, {len(array)}      ; Array length
    mov rax, [rsi]           ; Initialize max with first element
    
find_max:
    dec rcx
    cmp rcx, 0
    je max_done
    
    add rsi, 8               ; Move to next element
    mov rbx, [rsi]           ; Load element
    cmp rbx, rax             ; Compare with max
    jle find_max             ; Skip if not greater
    mov rax, rbx             ; Update max
    jmp find_max
    
max_done:
    ret
""")

asm.execute()
print(f"Maximum value: {asm.get('rax')}")
Output:
Maximum value: 23
09

Simple JIT Compiler

Build a basic JIT compiler that compiles and executes mathematical expressions at runtime

simple_jit.py
from tigerasm import TigerASM

class SimpleJIT:
    def __init__(self):
        self.asm = TigerASM()
        self.asm.setup("x86_64")
    
    def compile_expression(self, expr):
        # Simple expression parser: "a + b * c"
        # Supports: +, -, *, with operator precedence
        tokens = expr.replace('(', '').replace(')', '').split()
        
        self.asm.clear()
        code = []
        
        # Simple RPN (Reverse Polish Notation) evaluator
        # Convert: "2 + 3 * 4" -> handles precedence
        if '*' in tokens:
            # Handle multiplication first (precedence)
            idx = tokens.index('*')
            left = int(tokens[idx-1])
            right = int(tokens[idx+1])
            
            code.append(f"mov rax, {left}")
            code.append(f"mov rbx, {right}")
            code.append("imul rax, rbx")
            
            # Handle remaining addition
            if idx > 1 and tokens[idx-2] == '+':
                first = int(tokens[0])
                code.append(f"add rax, {first}")
        else:
            # Simple addition/subtraction
            num1 = int(tokens[0])
            op = tokens[1]
            num2 = int(tokens[2])
            
            code.append(f"mov rax, {num1}")
            if op == '+':
                code.append(f"add rax, {num2}")
            elif op == '-':
                code.append(f"sub rax, {num2}")
        
        code.append("ret")
        self.asm.asm('\n'.join(code))
        
    def execute(self):
        self.asm.execute()
        return self.asm.get('rax')

# Usage example
jit = SimpleJIT()

# Compile and execute: 5 + 3 * 4 = 17
jit.compile_expression("5 + 3 * 4")
print(f"Result: {jit.execute()}")

# Compile different expression: 100 - 25 = 75
jit.compile_expression("100 - 25")
print(f"Result: {jit.execute()}")
Output:
Result: 17
Result: 75

API Reference

Core Methods

TigerASM()
Create a new TigerASM instance with default configuration.
setup(arch: str = None)
Configure the target architecture. Auto-detects if not specified.
Parameters:
  • arch: Architecture name - "x86_64", "aarch64", etc.
asm(code: str, file=None)
Add assembly code to the program. Can accept code as string or from file.
Parameters:
  • code: Assembly source code as string
  • file: Optional file-like object to read from
execute()
Compile and execute the assembled code. Results are stored in registers.
clear()
Clear all assembly code and reset the executable buffer.

Register Operations

mov(register: str, value: int)
Set a register value directly in simulation mode.
Parameters:
  • register: Register name (e.g., "rax", "x0")
  • value: Value to set (64-bit integer)
get(register: str = "rax") -> int
Get the current value of a register.
Parameters:
  • register: Register name to read
Returns:
  • 64-bit integer value of the register
dump_regs() -> str
Get a formatted string of all x86_64 register values for debugging.

Memory Operations

write_mem(address: int, value: int, size: int)
Write data to virtual memory at specified address.
Parameters:
  • address: Memory address (0 to memory_size)
  • value: Value to write
  • size: Size in bytes (1, 2, 4, or 8)
read_mem(address: int, size: int) -> int
Read data from virtual memory.
Parameters:
  • address: Memory address to read from
  • size: Size in bytes (1, 2, 4, or 8)
write_bytes(address: int, data: bytes)
Write raw bytes to memory.
read_bytes(address: int, size: int) -> bytes
Read raw bytes from memory.
alloc(size: int) -> int
Allocate a zeroed memory block and return its address.
Returns:
  • Starting address of allocated block, or 0 if out of memory

File Operations

load_file(filename: str)
Load assembly code from a file.
load_binary_file(filename: str, address: int) -> int
Load binary data from file into memory at specified address.
Returns:
  • Number of bytes loaded
save_memory_to_file(filename: str, address: int, size: int)
Save a memory region to a binary file.
install(filename: str)
Save the compiled executable buffer to a file.

Supported Instructions

Data Movement

mov dst, src
Move data between registers/memory
push reg
Push register to stack
pop reg
Pop from stack to register

Arithmetic

add dst, src
Addition
sub dst, src
Subtraction
mul reg
Unsigned multiplication
imul dst, src
Signed multiplication
div reg
Unsigned division
inc reg
Increment register
dec reg
Decrement register
neg reg
Negate register

Logical Operations

and dst, src
Bitwise AND
or dst, src
Bitwise OR
xor dst, src
Bitwise XOR
not reg
Bitwise NOT
test dst, src
Logical compare (AND without storing)

Shifts & Rotates

shl reg, count
Shift left (logical)
shr reg, count
Shift right (logical)
sar reg, count
Shift right (arithmetic)
rol reg, count
Rotate left
ror reg, count
Rotate right

Control Flow

cmp dst, src
Compare operands
jmp label
Unconditional jump
je/jz label
Jump if equal/zero
jne/jnz label
Jump if not equal/zero
jg label
Jump if greater (signed)
jl label
Jump if less (signed)
ja label
Jump if above (unsigned)
jb label
Jump if below (unsigned)
call label
Call subroutine
ret
Return from subroutine
nop
No operation

Supported Instructions

Data Movement

mov dst, src
Move data between registers/memory
push reg
Push register to stack
pop reg
Pop from stack to register

Arithmetic

add dst, src
Addition
sub dst, src
Subtraction
mul reg
Unsigned multiplication
imul dst, src
Signed multiplication
div reg
Unsigned division
inc reg
Increment register
dec reg
Decrement register
neg reg
Negate register

Logical Operations

and dst, src
Bitwise AND
or dst, src
Bitwise OR
xor dst, src
Bitwise XOR
not reg
Bitwise NOT
test dst, src
Logical compare (AND without storing)

Shifts & Rotates

shl reg, count
Shift left (logical)
shr reg, count
Shift right (logical)
sar reg, count
Shift right (arithmetic)
rol reg, count
Rotate left
ror reg, count
Rotate right

Control Flow

cmp dst, src
Compare operands
jmp label
Unconditional jump
je/jz label
Jump if equal/zero
jne/jnz label
Jump if not equal/zero
jg label
Jump if greater (signed)
jl label
Jump if less (signed)
ja label
Jump if above (unsigned)
jb label
Jump if below (unsigned)
call label
Call subroutine
ret
Return from subroutine
nop
No operation

Device Support

TigerASM is built with cross-platform compatibility in mind, supporting multiple architectures and operating systems for maximum flexibility.

🏗️

Architecture Support

💻

x86_64 / AMD64

Full Support

Complete support for Intel and AMD 64-bit processors with full instruction set implementation.

  • ✓ All arithmetic and logical operations
  • ✓ Advanced bit manipulation
  • ✓ Memory addressing modes
  • ✓ Control flow instructions
  • ✓ Register state management
📱

ARM64 / AArch64

Full Support

Native support for ARM 64-bit architecture, perfect for Apple Silicon and ARM servers.

  • ✓ ARM instruction syntax
  • ✓ 31 general-purpose registers (x0-x30)
  • ✓ Branch and conditional instructions
  • ✓ SIMD operations ready
  • ✓ Apple M1/M2/M3 optimized
🖥️

Operating Systems

🪟

Windows

Supported
Windows 10 Windows 11 Server 2019+
🐧

Linux

Supported
Ubuntu 20.04+ Debian 11+ Fedora 35+ Arch Linux
🍎

macOS

Supported
macOS 11+ Intel & Apple Silicon Monterey, Ventura, Sonoma
🐧

BSD

Experimental
FreeBSD OpenBSD

Platforms & Devices

🖥️

Desktop Workstations

Intel Core, AMD Ryzen, Apple M-series

✓ Fully Supported
💼

Laptops

x86_64 and ARM64 laptops, MacBooks

✓ Fully Supported
☁️

Cloud Instances

AWS, Azure, GCP, DigitalOcean

✓ Fully Supported
🏢

Enterprise Servers

Data center x86_64 and ARM64 servers

✓ Fully Supported
🎮

Development Boards

Raspberry Pi 4/5, NVIDIA Jetson

⚠️ Limited Testing
📦

Containers

Docker, Kubernetes, LXC

✓ Fully Supported
🐍

Python Compatibility

3.8
Supported
3.9
Supported
3.12
Supported
3.13
Coming Soon
📋

System Requirements

🔧

Minimum Requirements

  • CPU: Any x86_64 or ARM64 processor
  • RAM: 256 MB available memory
  • Storage: 50 MB free space
  • Python: 3.8 or higher
  • OS: 64-bit operating system
🛠️

Build Dependencies

For building from source, you'll need the following tools:

🦀 Rust Toolchain

rustc 1.70.0 or higher

Install via: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

📦 Maturin

pip install maturin

PyO3 build tool for Rust-Python bindings

🔨 C/C++ Compiler

GCC, Clang, or MSVC

Required for linking native code

🐍 Python Dev Headers

python3-dev (Linux) / python-devel (Fedora)

Included with most Python installations

🚀

Performance Notes

Excellent

Native x86_64 Desktop

Intel Core i5+ or AMD Ryzen 5+

~1-2ms JIT compilation for typical programs
Excellent

Apple Silicon (M1/M2/M3)

Native ARM64 compilation

~1-2ms JIT compilation, superior power efficiency
Good

Cloud VM Instances

AWS EC2, Azure VM, GCP Compute

~2-5ms depending on instance type
Moderate

ARM Development Boards

Raspberry Pi 4/5

~5-10ms, suitable for prototyping

Installation Quick Reference

Platform
Architecture
Installation Method
Status
Windows
x86_64
pip install tigerasm
Ready
Linux
x86_64
pip install tigerasm
Ready
macOS
x86_64
pip install tigerasm
Ready
macOS
ARM64
pip install tigerasm
Ready
Linux
ARM64
pip install tigerasm
Ready
BSD
x86_64
Build from source
Experimental

Frequently Asked Questions

Find answers to common questions about TigerASM, installation, usage, and troubleshooting.

💡 General Questions

What is TigerASM? +

TigerASM is a high-performance runtime assembler for Python that allows you to write and execute assembly code directly in your Python programs. It supports both x86_64 and ARM64 architectures with JIT (Just-In-Time) compilation, virtual memory management, and full register control.

Why would I use TigerASM instead of pure Python? +

TigerASM is ideal for:

  • Performance-critical code sections requiring native speed
  • Low-level system programming and bit manipulation
  • Learning assembly programming in a Python environment
  • Building JIT compilers and runtime code generation
  • Prototyping CPU-specific optimizations
  • Educational purposes and assembly language teaching
Is TigerASM production-ready? +

TigerASM is stable and well-tested for x86_64 and ARM64 architectures. However, as with any low-level tool, thorough testing in your specific use case is recommended. It's currently best suited for performance optimization, educational projects, and prototyping rather than safety-critical applications.

What makes TigerASM different from other assemblers? +

TigerASM is unique because it:

  • Integrates seamlessly with Python via PyO3
  • Provides runtime JIT compilation
  • Includes virtual memory simulation (10MB)
  • Supports both x86_64 and ARM64 natively
  • Offers simple Python API for complex operations
  • Built with Rust for safety and performance

⚙️ Installation & Setup

How do I install TigerASM? +

Installation is simple via pip:

pip install tigerasm

For building from source:

git clone https://github.com/yourusername/tigerasm
cd tigerasm
pip install maturin
maturin develop --release
What are the system requirements? +

Minimum:

  • Any x86_64 or ARM64 processor
  • 256 MB RAM
  • 50 MB disk space
  • Python 3.8 or higher
  • 64-bit operating system

Recommended: 4+ core CPU, 2 GB RAM, Python 3.10 or 3.11

Does TigerASM work on my operating system? +

TigerASM supports:

  • Windows: 10, 11, Server 2019+
  • Linux: Ubuntu 20.04+, Debian 11+, Fedora 35+, Arch
  • macOS: 11+ (Big Sur and later), Intel and Apple Silicon
  • BSD: FreeBSD, OpenBSD (experimental)
Can I use TigerASM with virtual environments? +

Yes! TigerASM works perfectly with virtual environments:

python -m venv myenv
source myenv/bin/activate # or myenv\Scripts\activate on Windows
pip install tigerasm

🔧 Usage & Features

How do I choose between x86_64 and ARM64? +

TigerASM auto-detects your architecture by default. You can explicitly set it:

asm = TigerASM()
asm.setup("x86_64") # For Intel/AMD
# or
asm.setup("aarch64") # For ARM

Use asm.get_arch() to check the current architecture.

What assembly instructions are supported? +

TigerASM supports a comprehensive instruction set including:

  • Data Movement: mov, push, pop
  • Arithmetic: add, sub, mul, imul, div, inc, dec, neg
  • Logical: and, or, xor, not, test
  • Shifts: shl, shr, sal, sar, rol, ror
  • Control Flow: jmp, je, jne, jg, jl, call, ret
  • Comparison: cmp, test

See the Instructions section for the complete list.

How much memory can I use? +

TigerASM provides 10 MB of virtual memory (10,485,760 bytes) for your programs. This is sufficient for most use cases. You can:

  • Store data structures and arrays
  • Load binary files into memory
  • Allocate blocks with alloc()
  • Read/write with read_mem() and write_mem()
Can I debug my assembly code? +

Yes! TigerASM provides several debugging tools:

  • dump_regs() - Display all register values
  • get(register) - Check specific register values
  • read_mem() - Inspect memory contents
  • get_arch() - Verify architecture

You can also print intermediate values and step through execution by breaking your code into smaller segments.

How fast is TigerASM? +

TigerASM is very fast:

  • JIT Compilation: ~1-2ms for typical programs
  • Execution: Native CPU speed (no interpreter overhead)
  • Memory Access: Direct hardware access

Performance is comparable to hand-written C/C++ for the assembly portions.

🔍 Troubleshooting

I get "Unsupported architecture" error +

This error occurs if you're not on x86_64 or ARM64. TigerASM only supports 64-bit architectures. Check your system:

import platform
print(platform.machine())

Should output: "x86_64", "AMD64", "arm64", or "aarch64"

My assembly code doesn't execute correctly +

Common issues:

  • Missing 'ret': Always end with ret instruction
  • Wrong syntax: Check instruction format and operands
  • Label typos: Ensure jump targets match label names
  • Memory bounds: Verify addresses are within 0 to 10MB
  • Register names: Use correct names (rax, rbx for x86_64; x0, x1 for ARM)
"Memory address out of bounds" error +

This happens when accessing memory outside the 10MB range:

  • Valid range: 0 to 10,485,760 (0x000000 to 0xA00000)
  • Check your address calculations
  • Use memory_size() to verify bounds
  • Use alloc() for safe memory allocation
Installation fails with compiler errors +

If building from source fails:

  • Install Rust: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Update Rust: rustup update
  • Install build tools:
    • Linux: sudo apt install build-essential
    • macOS: xcode-select --install
    • Windows: Install Visual Studio Build Tools
Can I use floating-point operations? +

Floating-point support is not currently implemented. TigerASM focuses on integer operations. For floating-point math, use Python's native capabilities or libraries like NumPy alongside TigerASM.

🚀 Advanced Topics

Can I call Python functions from assembly? +

Direct calls are not supported, but you can:

  • Execute assembly, return to Python, process results
  • Use memory as shared data structure
  • Store function pointers in registers for simple callbacks
  • Split complex operations between Python and assembly
How do I build a JIT compiler with TigerASM? +

Check out Example 9 (Simple JIT Compiler) in the Examples section! The basic approach:

  1. Parse your input language/expressions
  2. Generate assembly code as strings
  3. Use asm.asm() to load the code
  4. Call execute() to run it
  5. Retrieve results from registers
Is TigerASM thread-safe? +

Each TigerASM instance is independent. For multi-threaded use:

  • Create separate TigerASM instances per thread
  • Don't share instances between threads
  • Virtual memory is per-instance (isolated)
  • Use Python's threading primitives for synchronization if needed
Can I save compiled code for later use? +

Yes! Use the install() method:

asm.execute() # Compile first
asm.install("compiled.bin") # Save to file

Note: The saved file is platform-specific and may not be directly executable outside TigerASM.

💬 Community & Support

Where can I get help? +

Support channels:

  • GitHub Issues: Bug reports and feature requests
  • Documentation: This comprehensive guide
  • Examples: Working code samples in the Examples section
  • Stack Overflow: Tag your questions with "tigerasm"
Can I contribute to TigerASM? +

Absolutely! Contributions are welcome:

  • Submit pull requests on GitHub
  • Report bugs and issues
  • Improve documentation
  • Add examples and tutorials
  • Share your projects built with TigerASM
What license is TigerASM under? +

TigerASM is released under the MIT License. You can use it freely in personal and commercial projects, with attribution.

Is there a Discord or Slack community? +

Community channels are being set up! Check the GitHub repository for the latest links to Discord, Slack, or other community platforms.

Still have questions?

Can't find what you're looking for? Reach out to us!