agentleFS
mohitmishra786mohitmishra786/low-level-dev-skills/skills/computer-architecture/abi-and-calling-conventions/SKILL.md

abi-and-calling-conventions

Skill290 starsChanged 7 months agoMITView on GitHub

ABI and calling conventions skill for cross-language boundaries. Use when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Activates on queries about calling convention, ABI, System V AMD64, AAPCS, stack frame, variadic function, or FFI registers.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Document application binary interface (ABI) rules: register roles, stack alignment, argument passing, return values, and variadic …

    line 10

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

ABI and Calling Conventions

Purpose

Document application binary interface (ABI) rules: register roles, stack alignment, argument passing, return values, and variadic conventions across System V AMD64, ARM AAPCS, and RISC-V — essential for assembly, FFI, and debugging.

When to Use

  • Writing assembly thunks or inline asm clobbers
  • Debugging corrupted stack in mixed C/asm
  • FFI between Rust/C/Zig (skills/rust/rust-ffi, skills/zig/zig-cinterop)
  • Reading disassembly from skills/debuggers/gdb

Workflow

1. System V AMD64 (Linux/macOS)

ItemRule
Integer argsrdi, rsi, rdx, rcx, r8, r9
XMM argsxmm0–xmm7 (float)
Return int/ptrrax (+ rdx for 128-bit)
Stack alignment16-byte before call
Red zone128 bytes below rsp (Linux)
Callee-savedrbx, rbp, r12–r15
/* void foo(int a, int b, int c, int d, int e, int f, int g); */
/* a–f in regs, g on stack */

Windows x64 differs — see skills/compilers/msvc-cl.

2. ARM AAPCS (AArch32/AArch64)

AArch64:

ItemRule
Integer argsx0–x7
Float argsv0–v7
Returnx0/x1 or v0
Stack align16-byte
Callee-savedx19–x28, fp (x29), lr (x30)

Thumb interworking: LSB of function pointer set for Thumb code.

See skills/low-level-programming/assembly-arm.

3. RISC-V psABI (RV64)

ItemRule
Integer argsa0–a7
Callee-saveds0–s11, sp
Returna0, a1
Stack align16-byte

See skills/low-level-programming/assembly-riscv.

4. Stack frame layout (conceptual)

high addresses
├── return address
├── saved frame pointer
├── local variables
├── spill slots / alignment padding
└── outgoing args (if any)
low addresses (rsp)

5. Variadic functions

System V: al holds number of vector args used; register_save_area on stack for va_start. Prefer typed wrappers over raw va_arg in portable FFI.

6. Verify in compiler output

gcc -O2 -S -o - foo.c   # study .cfi_* and mov args
objdump -d -M intel ./a.out

7. Agent usage

/abi-and-calling-conventions Which registers hold args 5–8 in AArch64 for my C function?

Common Problems

SymptomCauseFix
Crash on callStack misalignedAlign rsp mod 16
Wrong float argXMM vs GPR mismatchMatch prototype
Corrupt callee-savedAsm clobber missingList in clobber or save
FFI garbageWindows vs SysV mixMatch toolchain ABI
Variadic UBWrong type to va_argCast to promoted type

Related Skills

  • skills/low-level-programming/assembly-x86 — x86-64 asm
  • skills/low-level-programming/assembly-arm — AAPCS examples
  • skills/low-level-programming/assembly-riscv — RISC-V asm
  • skills/rust/rust-ffi — extern "C" guarantees
  • skills/binaries/elf-inspection — symbol and relocation views

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.