Loading...
Loading...
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 assembly, AT&T vs Intel syntax, inline asm, calling conventions, SIMD intrinsics, or reading disassembly output from objdump or GDB.
npx skill4agent add mohitmishra786/low-level-dev-skills assembly-x86%rsp%rbp# AT&T syntax (GCC default)
gcc -S -O2 -fverbose-asm foo.c -o foo.s
# Intel syntax
gcc -S -masm=intel -O2 foo.c -o foo.s
# From GDB
(gdb) disassemble /s main # with source
(gdb) x/20i $rip
# From objdump
objdump -d -M intel -S prog # Intel + source (needs -g)| 64-bit | 32-bit | 16-bit | 8-bit high | 8-bit low | Purpose |
|---|---|---|---|---|---|
| | | | | Return value / accumulator |
| | | | | Callee-saved |
| | | | | 4th arg / count |
| | | | | 3rd arg / 2nd return |
| | | — | | 2nd arg |
| | | — | | 1st arg |
| | | — | | Frame pointer (callee-saved) |
| | | — | | Stack pointer |
| | | — | | 5th–8th args / caller-saved |
| | | — | | Callee-saved |
| Instruction pointer | ||||
| | Status flags | |||
| FP/SIMD args and return | ||||
| Caller-saved SIMD | ||||
| AVX 256-bit | ||||
| AVX-512 512-bit |
%rdi, %rsi, %rdx, %rcx, %r8, %r9%xmm0%xmm7%rax%rdx%xmm0%xmm1%rax, %rcx, %rdx, %rsi, %rdi, %r8–%r11, %xmm0–%xmm15%rbx, %rbp, %r12–%r15callcall%rsp%rsp| Pattern | Meaning |
|---|---|
| Copy rdi to rax |
| Load 8 bytes from address in rdi |
| Store rax to rdi+8 |
| Load effective address rdi+8 into rax (no memory access) |
| Push rbx; rsp -= 8 |
| Pop into rbx; rsp += 8 |
| Push return addr; jmp foo |
| Pop return addr; jmp to it |
| Zero rax (smaller encoding than |
| Set ZF if rax == 0 (cheaper than |
| Set flags for rdi - 5 |
| Jump if signed less than |
| Feature | AT&T | Intel |
|---|---|---|
| Operand order | source, dest | dest, source |
| Register prefix | | |
| Immediate prefix | | |
| Memory operand | | |
| Size suffix | | — (inferred) |
-masm=intel// Basic: increment a register
int x = 5;
__asm__ volatile (
"incl %0"
: "=r"(x) // outputs: =r means write-only register
: "0"(x) // inputs: 0 means same as output 0
: // clobbers: none
);
// CPUID example
uint32_t eax, ebx, ecx, edx;
__asm__ volatile (
"cpuid"
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
: "a"(1) // input: leaf 1
);
// Atomic increment
static inline int atomic_inc(volatile int *p) {
int ret;
__asm__ volatile (
"lock; xaddl %0, %1"
: "=r"(ret), "+m"(*p)
: "0"(1)
: "memory"
);
return ret + 1;
}"r""m""i""a""b""c""d""=""+""memory"#include <immintrin.h> // includes all x86 SIMD headers
// Add 8 floats at once with AVX
__m256 a = _mm256_loadu_ps(arr_a); // load 8 floats (unaligned)
__m256 b = _mm256_loadu_ps(arr_b);
__m256 c = _mm256_add_ps(a, b);
_mm256_storeu_ps(result, c);-mavx2-march=native__builtin_cpu_supports("avx2")skills/low-level-programming/assembly-armskills/compilers/gcc-S -masm=intelskills/debuggers/gdbsinix/i