Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/momumi/x86-zig
library for assembling x86 in zig (WIP)
https://github.com/momumi/x86-zig
Last synced: about 1 month ago
JSON representation
library for assembling x86 in zig (WIP)
- Host: GitHub
- URL: https://github.com/momumi/x86-zig
- Owner: momumi
- License: unlicense
- Created: 2020-02-02T05:02:44.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-30T02:58:19.000Z (over 3 years ago)
- Last Synced: 2024-08-02T22:27:33.607Z (4 months ago)
- Language: Zig
- Homepage:
- Size: 826 KB
- Stars: 26
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-zig - momumi/x86-zig
- awesome-zig - x86-zig🗒️library for assembling x86 in zig (WIP)
README
# x86-zig
A library for assembling x86 instructions written in zig.
## Example
```zig
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
* Public domain ([UNLICENSE](UNLICENSE) or https://unlicense.org/)
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)at your option.