Skip to content

Instantly share code, notes, and snippets.

@travisstaloch
Created December 14, 2019 03:39
Show Gist options
  • Save travisstaloch/b2a5edb5bd003b85214a9e6e2fe615f0 to your computer and use it in GitHub Desktop.
Save travisstaloch/b2a5edb5bd003b85214a9e6e2fe615f0 to your computer and use it in GitHub Desktop.
stripped down template for viewing assembly produced by zig
// zig build-obj --emit asm --strip --release-small view_asm.zig && cat view_asm.s
const std = @import("std");
pub fn panic(msg: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
while (true) {}
}
export nakedcc fn _start() noreturn {
// code here will appear in _start section
// unless it isn't used
aeou() catch unreachable;
std.os.exit(0);
// while (true) {}
}
fn aeou() !void {
_ = try std.os.write(1, "hello world\n");
}
// to build exe. first create view_asm.o then create exe
// zig build-obj --strip --release-small view_asm.zig
// zig build-exe --object view_asm.o --name view_asm
// one liner
// zig build-obj --strip --release-small view_asm.zig && zig build-exe --object view_asm.o --name view_asm && ./view_asm
// disassemble with objdump
// objdump -d view_asm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment