Skip to content
Skills Library
Programming · Building & coding

assembly

/assembly

Expert x86-64 and ARM64 assembly assistance covering registers, calling conventions, stack frames, and inline asm. Use when writing low-level code, optimizing hot loops, or reverse engineering binaries.

Licence
MIT
Last repository change
01.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Expert x86-64 and ARM64 assembly assistance covering registers, calling conventions, stack frames, and inline asm. Use when writing low-level code, optimizing hot loops, or reverse engineering binaries.

Original author description

Expert x86-64 and ARM64 assembly assistance covering registers, calling conventions, stack frames, and inline asm. Use when writing low-level code, optimizing hot loops, or reverse engineering binaries.

How it works

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Original SKILL.md headings · 138 lines, 701 words
SKILL.md preview
---
name: assembly
description: Expert x86-64 and ARM64 assembly assistance covering registers, calling conventions, stack frames, and inline asm. Use when writing low-level code, optimizing hot loops, or reverse engineering binaries.
---

# Assembly

Low-level language with a very strong correspondence between the instruction in the language and the architecture's machine code instructions.

## When to Use

- **Low-Level Hardware & OS Kernel Programming**: Writing bootloaders, CPU context switches, interrupt handlers, and page table setup.
- **Micro-Architectural SIMD Vector Optimization**: Crafting hand-tuned AVX-512, Neon, or SSE assembly kernels for game physics and matrix multiplication.
- **Reverse Engineering & Exploit Analysis**: Disassembling binary executables to audit firmware, analyze malware, or debug compiler crashes.
- **Embedded Bare-Metal Firmware**: Direct CPU register manipulation on microcontrollers without operating system abstractions.

## Quick Start

```assembly
section .data
    msg db "Hello, World!", 0xa
    len equ $ - msg

section .text
    global _start

_start:
    mov rax, 1      ; write syscall
    mov rdi, 1      ; stdout
    mov rsi, msg    ; buffer
    mov rdx, len    ; length
    syscall

    mov rax, 60     ; exit syscall
    xor rdi, rdi    ; exit code 0
    syscall
```

## Core Concepts

### CPU Registers & Memory Addressing Modes (x86-64 / ARM64)

Registers hold immediate state for execution; addressing modes compute memory operands:

```nasm
; x86-64 NASM: Moving data and base-index-scale-displacement addressing
mov rax, 42                     ; Immediate to register
mov rbx, [rsp + 16]             ; Base + displacement
mov rcx, [rdi + rsi * 8 + 32]   ; Base + index * scale + displacement
```

### The System V AMD64 Calling Convention

Governs how functions receive parameters and return values in Linux and macOS:

| Register   | Argument Role                              |
| :--------- | :----------------------------------------- |
| `rdi`      | 1st function argument                      |
| `rsi`      | 2nd function argument                      |
| `rdx`      | 3rd function argument                      |
| `rcx`      | 4th function argument                      |
| `r8`, `r9` | 5th and 6th function arguments             |
| `rax`      | Function return value (and syscall number) |

```nasm
; Direct 64-bit Linux syscall (sys_write = 1)
mov rax, 1          ; syscall: sys_write
mov rdi, 1          ; file descriptor: stdout (1)
mov rsi, msg        ; pointer to buffer
mov rdx, 14         ; count (bytes)
syscall             ; invoke kernel
```

### SIMD Vectorization (AVX-512 / AVX2)

Processes multiple data elements simultaneously across 256-bit or 512-bit vector registers:

```nasm
; Add 8 single-precision floats in parallel using AVX
vmovups ymm0, [rdi]        ; Load 8 floats into YMM0
vmovups ymm1, [rsi]        ; Load 8 floats into YMM1
vaddps  ymm2, ymm0, ymm1   ; YMM2 = YMM0 + YMM1 in single clock cycle
vmovups [rdx], ymm2        ; Store result
```

## Common Patterns

### Syscall Invocation with Proper Register Arguments (Linux x86-64)

**Problem**: Invoking kernel system calls directly without C runtime dependencies.

**Solution**:
Load syscall number into `rax` and arguments in `rdi, rsi, rdx, r10, r8, r9`:

```nasm
section .text
global _start

_start:
    ; sys_write(fd: 1, buf: msg, len: 14)
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, 14
    syscall

    ; sys_exit(code: 0)
    mov rax, 60
    xor rdi, rdi
    syscall

section .data
msg db "Hello, Assembly", 10
```

## Best Practices

**Do**:

- Preserve Callee-Saved Registers: Always preserve `rbx`, `rsp`, `rbp`, `r12`-`r15` across function boundaries.
- Maintain 16-Byte Stack Alignment: Ensure `rsp` is 16-byte aligned before issuing `call` instructions to avoid segmentation faults in libc.
- Use Inline Assembly Sparingly in C/Rust: Rely on compiler intrinsic headers (`<immintrin.h>`) whenever possible instead of raw inline assembly.
- Comment Every Assembly Routine Thoroughly: Document input register assumptions, output registers, and modified flags.

**Don't**:

- Rewrite algorithms in assembly without profiling: Modern LLVM/GCC compilers generate near-optimal machine code for standard loops.
- Ignore processor architecture differences: x86-64 CISC code is incompatible with ARM64 RISC instruction sets.
- Bypass platform calling conventions: Mixing calling conventions causes silent stack corruption and elusive crashes.

## Troubleshooting

| Error                                                 | Cause                                                                   | Solution                                                             |
| :---------------------------------------------------- | :---------------------------------------------------------------------- | :------------------------------------------------------------------- |
| `Segmentation fault (core dumped)`                    | Dereferencing invalid pointer or misaligned stack before `call`.        | Ensure stack pointer `rsp` is 16-byte aligned before function calls. |
| `Undefined reference to '_start'`                     | Linker entrypoint missing or `global _start` not exported.              | Declare `global _start` or compile with `gcc -nostartfiles`.         |
| `relocation R_X86_64_32S against ... can not be used` | Position-independent executable (PIE) requires RIP-relative addressing. | Use `[rel symbol]` addressing in NASM.                               |

## References

- [x86 Assembly Guide](https://www.cs.virginia.edu/~evans/cs216/guides/x86.html)

Versions

RepositoryScoreLicence
This page · G1Joshi/Agent-Skills100MIT
dkbnull/hello-skill86MIT

Database snapshot: 13.11.2026 · package version 341cb7824b6a (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95lang-assembly
    Use this skill when the user says 'assembly', 'asm', 'x86-64', 'ARM64', 'AArch64', 'calling convention', 'System V ABI', 'Windows x64 ABI', 'registers', 'read disassembly', 'objdump', 'Compiler Explorer', 'inline asm', 'stack frame'. Reads and writes x86-64 and AArch64 assembly:…
  • 100asm-patterns
    Assembly language patterns, calling conventions, and code structure for x86-64 and ARM64. Use when writing, reviewing, or generating .asm/.s/.S files; when implementing functions that interoperate with C/system code; or when establishing correct prologues, epilogues, stack…
  • 100assembly-x86
    x86-64 assembly skill for reading, writing, and debugging assembly code. Use when reading GCC/Clang assembly output, writing inline asm in C/C++, understanding the System V AMD64 ABI calling convention, or debugging register and stack state. Activates on queries about x86-64…
  • 100assembly-arm
    Use when reading or writing AArch64 or AArch32 Thumb assembly, inline asm in C, AAPCS64 register roles, or NEON and SVE vector code. Not for ABI detail across ISAs: use abi-and-calling-conventions.
  • 95assembly-x86
    Use when reading GCC or Clang x86-64 assembly, writing inline asm, decoding AT&T syntax, or applying System V AMD64 register rules. Not for SIMD intrinsic selection.
  • 100assembly-arm
    AArch64 and ARM assembly skill for reading and writing ARM assembly code. Use when reading GCC/Clang output for AArch64 or ARM Thumb targets, writing inline asm in C/C++, understanding the ARM ABI (AAPCS64/AAPCS), or debugging register and stack state on ARM hardware or QEMU.…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.