Explain Assembly code

Paste assembly from a debugger or Compiler Explorer and Vibe explains it in plain English: which register holds which C variable, how subs and b.ne make a loop, and what changes between -O0, -O1 and -O2.

sum.s

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe25 lines selected

Press Explain it for the sample, or paste your own code first.

What this Assembly sample shows

registers and arguments
The C names are gone, and registers hold the values. Arm's calling convention, the AAPCS64, passes the first 8 integer and pointer arguments in x0 to x7 and returns the result in x0, so nums arrives in x0, count in w1, and mov x0, x8 hands back the total. w1 is the low 32 bits of x1, the size of an int. A caller built the same way put the array's address in x0 and 4 in w1, then jumped to _sum.
compare and branch
cmp w1, #1 and b.lt LBB0_4 skip the loop when count is less than 1, and LBB0_4 returns 0. The loop is the 4 instructions after LBB0_2: ldr w10, [x0], #4 loads one int and moves x0 4 bytes on to the next one, add adds it to the total in w8, subs takes 1 off a copy of count in x9, and b.ne jumps back until that copy reaches 0. No register counts i up: the compiler counts down instead.
-O0 and -O1
At -O0 the same function was 25 instructions, with a loop of 16. It kept nums, count, total and i in memory on the stack and loaded them again on every pass: 13 of its instructions read or write [sp, ...]. At -O1 it was 13 instructions with a loop of 4, and none of them touched the stack.
arm64 and x86-64
The same C built for x86-64 Linux is a different instruction set: testl and jle instead of cmp and b.lt, nums in rdi and count in esi, and a loop that adds straight from memory with one addl (%rdi,%rdx,4), %eax. Every arm64 instruction took 4 bytes, and the x86-64 ones took 1 to 6. Linked with a test main and run, it returned 16 for 3, 5, -2 and 10, 0 for a count of 0 or -3, and 703 for the numbers 1 to 37.

Good to know

  • Built with clang 22.1.8 on Linux. clang --target=arm64-apple-macos -O1 -S writes assembly text instead of building a program, so no Mac was needed. The sample is the _sum function from that output with the C added as ; comments. Left out: .p2align 2, .cfi_startproc, .cfi_endproc, 3 ; %bb.N: block comments and the output's first 2 and last 2 lines. The trimmed text still assembled to the same 13 instructions, byte for byte. The arm64 code wasn't run: the results come from x86-64 builds of the same C, run on Linux.
  • At -O2 the function grew to 62 instructions and 3 loops. The main loop loads 4 128-bit q registers per pass, adds them with add.4s and counts down by 16, so it takes 16 ints at a time. A second loop takes 4 at a time, and the -O1 loop is left for the last few. The x86-64 -O2 build still returned the same 4 results.
  • Apple's guide Writing ARM64 code for Apple platforms (developer.apple.com) says macOS follows the 64-bit Arm standard apart from a few listed differences, such as x18 being reserved. None of them changes the registers used here.

Watch out: The function you're looking for may not be in the assembly at all. With sum and a main that calls it in one file, -O1 turned main into 2 instructions, mov w0, #16 and ret: the compiler worked out the total of 3, 5, -2 and 10 itself, and nothing calls sum, though it is still in the file. In the x86-64 build, a gdb breakpoint on sum never stopped, and the program exited with 16. At -O0, main calls sum.

Explain Assembly code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done.
    macOS dialog: Unvibe Not Opened, with Done and Move to Trash
    Real screen, macOS 15
  3. System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open