# Studying assembly output

**URL:** <https://ziggit.dev/t/studying-assembly-output/2554>\
**Category:** Help\
**Created:** [December 23, 2023, 8:52am UTC](https://ziggit.dev/t/studying-assembly-output/2554 "2023-12-23T08:52:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgirod](https://ziggit.dev/user_avatar/ziggit.dev/tgirod/32/3744_2.png) [@tgirod](https://ziggit.dev/u/tgirod)\
**Post date:** [December 23, 2023, 8:52am UTC](https://ziggit.dev/t/studying-assembly-output/2554/1 "2023-12-23T08:52:25Z")

</div>

After a few excellent weeks playing with zig, I feel like going one step further and looking at assembly output, comparing design choices.

Do you have suggestions for tools and workflows ? I’ve used godbolt a bit, but it is really slow and rather tedious to use on my small laptop screen …

---

<div class="post-metadata">

**Author:** ![permutationlock](https://ziggit.dev/user_avatar/ziggit.dev/permutationlock/32/9958_2.png) [@permutationlock](https://ziggit.dev/u/permutationlock)\
**Post date:** [December 23, 2023, 9:21am UTC](https://ziggit.dev/t/studying-assembly-output/2554/2 "2023-12-23T09:21:24Z")

</div>

Well `zig build-exe`, `zig build-lib`, etc have `-femit-asm` which is pretty useful.

---

<div class="post-metadata">

**Author:** ![tgirod](https://ziggit.dev/user_avatar/ziggit.dev/tgirod/32/3744_2.png) [@tgirod](https://ziggit.dev/u/tgirod)\
**Post date:** [December 23, 2023, 9:27am UTC](https://ziggit.dev/t/studying-assembly-output/2554/3 "2023-12-23T09:27:28Z")

</div>

Yes, I tried that yesterday but I got lost in the huge amount of code generated. Are you using tools to make the analysis easier ? For example matching a function with its aim counterpart ?

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [December 23, 2023, 10:58am UTC](https://ziggit.dev/t/studying-assembly-output/2554/4 "2023-12-23T10:58:34Z")

</div>

As an option:

```plaintext
zig build-exe file.zig -fstrip
objdump -d file > file.s

```

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [December 23, 2023, 11:51am UTC](https://ziggit.dev/t/studying-assembly-output/2554/5 "2023-12-23T11:51:51Z")

</div>

> [@tgirod](#):
>
> but I got lost in the huge amount of code generated

Below is a comparison of output files’ sizes (in bytes)  
depending on compilation options (just out of curiosity):

```zig
                                          h h.s
-femit-asm -O ReleaseSafe : 2_030_376 5_784_599
-femit-asm : 1_926_728 5_696_145
-femit-asm -O ReleaseFast : 1_787_672 4_473_742
-femit-asm -fstrip : 53_912 320_732
-femit-asm -O ReleaseSafe -fstrip : 17_048 60_478
-femit-asm -O ReleaseFast -fstrip : 12_952 27_023
-femit-asm -O ReleaseSmall : 8_856 32_355
-femit-asm -O ReleaseSmall -fstrip : 8_856 32_355

```

h.zig:

```zig
const std = @import("std");
pub fn main() void {
    std.debug.print("Hello!\n", .{});
}

```

`h` - executable  
`h.s` - asm

---

<div class="post-metadata">

**Author:** ![andrewrk](https://ziggit.dev/user_avatar/ziggit.dev/andrewrk/32/7011_2.png) [@andrewrk](https://ziggit.dev/u/andrewrk)\
**Post date:** [December 25, 2023, 5:10am UTC](https://ziggit.dev/t/studying-assembly-output/2554/6 "2023-12-25T05:10:14Z")

</div>

Note that strip is enabled by default for `-OReleaseSmall`, and you can use `-fno-strip` in combination with `-OReleaseSmall`.

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [December 25, 2023, 6:19pm UTC](https://ziggit.dev/t/studying-assembly-output/2554/7 "2023-12-25T18:19:11Z")

</div>

I usually compile with ReleaseFast, with .pdb enabled, and put a breakpoint in the function that I want to analyze. Depending on what it is you’re trying to examine, ReleaseSmall might be better, simply because the code is smaller, but then you have to take into consideration what Andrew mentioned above.  
I usually do this with VSCode, but binary debugging is an afterthought there, it’s not very ergonomic. When I need to get serious with disassembly, I use x64dbg. It’s intended for debugging with no source code, so the way it displays binary information is excellent.

---

<div class="post-metadata">

**Author:** ![Enzy](https://ziggit.dev/user_avatar/ziggit.dev/enzy/32/8185_2.png) [@Enzy](https://ziggit.dev/u/Enzy)\
**Post date:** [April 3, 2026, 10:13pm UTC](https://ziggit.dev/t/studying-assembly-output/2554/8 "2026-04-03T22:13:15Z")

</div>

Adding to the previous comment, you can use rizin - which is a fork of radare2 - instead of x64dbg as a more cross-platform alternative (e.g. Linux). Set a `@breakpoint()`, compile with ReleaseFast and hop into your binary with `rizin -d <exe>`, `dc` to run your program and then print the disassembly with `pd`. You can also enter visual mode and look around the assembly. What puts this apart from disassembling with lldb or objdump directly is that it prints some cool branch target lines so that you can see where your loops are. Also the visual mode is cool to look around, like the `tui` mode in gdb (lldb has smth similar… not sure). They also have a GUI (Cutter). I noticed that zig aggressively inlines your functions so looking at the assembly it is really hard to tell where you are, lldb and rizin show some source code comments on the right but its still no 1-to-1 mapping.

Tbh I was just having fun looking at assembly, but just wanted to put it out here nevertheless , even though its been 2 years :\>
