One-liners

Contents

One-liners#

Single-instruction (or close to it) x86-64 idioms.

Zero a register cheaply; the encoder special-cases xor self-reg.

xor     rax, rax

Set a register to a constant via mov.

mov     rax, 0x4142434445464748

Align the stack to 16 bytes before a call (System V ABI).

and     rsp, -16

Linux write(1, "hi\n", 3) syscall.

mov     rax, 1                  ; sys_write
mov     rdi, 1                  ; stdout
lea     rsi, [rel msg]
mov     rdx, 3
syscall

Linux exit(0) syscall.

mov     rax, 60                 ; sys_exit
xor     rdi, rdi
syscall

Read the timestamp counter (cycle-accurate microbench).

rdtsc                            ; result in edx:eax

Query a CPU feature (here, vendor string in eax=0).

mov     eax, 0
cpuid                            ; ebx, edx, ecx hold "GenuineIntel" / "AuthenticAMD"

Memory fence; orders prior loads and stores against subsequent ones.

mfence

References#

  • Snippets for the snippets catalogue.

  • Operators for the encoded forms of these instructions.

  • I/O for the syscall convention.