Skip to content
/ x86-zig Public

library for assembling x86 in zig (WIP)

License

Unlicense, Apache-2.0 licenses found

Licenses found

Unlicense
UNLICENSE
Apache-2.0
LICENSE-APACHE
Notifications You must be signed in to change notification settings

momumi/x86-zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

x86-zig

A library for assembling x86 instructions written in zig.

Example

const warn = @import("std").debug.warn;

const x86 = @import("src/x86.zig");

pub fn main() anyerror!void {
    const machine64 = x86.Machine.init(.x64);

    // MOV RAX, R15
    {
        const op1 = x86.Operand.register(.RAX);
        const op2 = x86.Operand.register(.R15);
        const instr = try machine64.build2(.MOV, op1, op2);
        warn("{x}\t\t\tMOV\t\t{}, {}\n", .{instr.asSlice(), op1, op2});
    }

    // LOCK MOV DWORD PTR FS:[8*ECX + EBX + 0x33221100], EAX
    {
        const op1 = x86.Operand.memorySib(.FS, .DWORD, 8, .ECX, .EBX, 0x33221100);
        const op2 = x86.Operand.register(.EAX);
        const instr = try machine64.build2_pre(.Lock, .MOV, op1, op2);
        warn("{x}\tLOCK MOV\t{}, {}\n", .{instr.asSlice(), op1, op2});
    }

    // JMP -20
    {
        const op1 = x86.Operand.immediateSigned(-20);
        const instr = try machine64.build1(.JMP, op1);
        warn("{x}\t\t\tJMP\t\t{}\n", .{instr.asSlice(), op1});
    }
}

Building examples

example-hello

Assembles, loads to RAM, and executes a simple hello world program (Linux-x64).

zig build example-hello

License

Licensed under either of

at your option.

About

library for assembling x86 in zig (WIP)

Resources

License

Unlicense, Apache-2.0 licenses found

Licenses found

Unlicense
UNLICENSE
Apache-2.0
LICENSE-APACHE

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages