sBPF BooksBPF Book
Program Development

Instruction Set

Every sBPF instruction this book uses, with syntax, operand types, and alignment rules.

Compact reference. For teaching-style introductions to these instructions, see Assembly → Instructions.

The Opcode column is the byte the assembler emits for each instruction. Read it when staring at a disassembly or debugging an unfamiliar binary. Two entries per ALU and jump instruction reflect the two source modes: the lower opcode is the immediate-source form, the higher one is the register-source form.

Data movement

MnemonicOpcodeSyntaxSemantics
mov640xb7 / 0xbfmov64 dst, srcdst = src (src is register or 32-bit imm)
lddw0x18lddw rN, IMMrN = IMM (64-bit imm or label address; 16-byte instruction)
ldxb0x71ldxb rN, [base + off]read 1 byte (zero-extend)
ldxh0x69ldxh rN, [base + off]read 2 bytes (zero-extend)
ldxw0x61ldxw rN, [base + off]read 4 bytes (zero-extend)
ldxdw0x79ldxdw rN, [base + off]read 8 bytes
stxb0x73stxb [base + off], srcwrite low 1 byte of src
stxh0x6bstxh [base + off], srcwrite low 2 bytes of src
stxw0x63stxw [base + off], srcwrite low 4 bytes of src
stxdw0x7bstxdw [base + off], srcwrite 8 bytes of src

Memory addressing: [base + offset] where base is a register and offset is a signed 16-bit immediate (-32768 to +32767). Operation must be naturally aligned for its size.

Arithmetic (64-bit)

MnemonicOpcodeSyntaxSemantics
add640x07 / 0x0fadd64 dst, srcdst = dst + src
sub640x17 / 0x1fsub64 dst, srcdst = dst - src
mul640x27 / 0x2fmul64 dst, srcdst = dst * src
div640x37 / 0x3fdiv64 dst, srcdst = dst / src (unsigned)
sdiv640xe7 / 0xefsdiv64 dst, srcdst = dst / src (signed)
mod640x97 / 0x9fmod64 dst, srcdst = dst % src (unsigned)
and640x57 / 0x5fand64 dst, srcbitwise AND
or640x47 / 0x4for64 dst, srcbitwise OR
xor640xa7 / 0xafxor64 dst, srcbitwise XOR
lsh640x67 / 0x6flsh64 dst, srcdst <<= src (logical)
rsh640x77 / 0x7frsh64 dst, srcdst >>= src (logical)
arsh640xc7 / 0xcfarsh64 dst, srcdst >>= src (arithmetic, sign-extend)
neg640x87neg64 dstdst = -dst

src can be a register or a 32-bit immediate.

32-bit variants exist (drop the 64 suffix): operate on the low 32 bits and zero the upper 32. Almost never needed in Solana programs.

Control flow

MnemonicOpcodeSyntaxJumps if
jeq0x15 / 0x1djeq dst, src, labeldst == src
jne0x55 / 0x5djne dst, src, labeldst != src
jgt0x25 / 0x2djgt dst, src, labeldst > src (unsigned)
jge0x35 / 0x3djge dst, src, labeldst >= src (unsigned)
jlt0xa5 / 0xadjlt dst, src, labeldst < src (unsigned)
jle0xb5 / 0xbdjle dst, src, labeldst <= src (unsigned)
jsgt0x65 / 0x6djsgt dst, src, labeldst > src (signed)
jsge0x75 / 0x7djsge dst, src, labeldst >= src (signed)
jslt0xc5 / 0xcdjslt dst, src, labeldst < src (signed)
jsle0xd5 / 0xddjsle dst, src, labeldst <= src (signed)
jset0x45 / 0x4djset dst, src, label(dst & src) != 0
ja0x05ja labelunconditional

dst is always a register. src is a register or 32-bit immediate. Falls through on false.

Syscall and exit

MnemonicOpcodeSyntaxSemantics
call0x85call <name>invoke a runtime syscall; args in r1-r5, return in r0; clobbers r1-r5; preserves r6-r9
exit0x95exitend program; runtime reads exit code from r0

Endian (le / be)

MnemonicOpcodeSyntaxSemantics
le0xd4le16 dst / le32 dst / le64 dstbyte-swap to little-endian; on Solana this is a mask, not a swap
be0xdcbe16 dst / be32 dst / be64 dstbyte-swap to big-endian; this is the only direction that actually swaps

Solana runs little-endian, so le{n} reduces to masking the low n bits. Use be{n} when you genuinely need network-order bytes (parsing certain external formats); skip these otherwise.

Register conventions

RegisterRoleVolatility across call
r0exit code + syscall return valueclobbered
r1first syscall arg; on entry, input region pointerclobbered
r2second syscall argclobbered
r3third syscall argclobbered
r4fourth syscall argclobbered
r5fifth syscall argclobbered
r6general purposepreserved
r7general purposepreserved
r8general purposepreserved
r9general purposepreserved
r10read-only stack pointerpreserved

Encoding

Every instruction is exactly 8 bytes, with one exception:

  • lddw is 16 bytes (it carries a 64-bit immediate).

This means program size in bytes ≈ instruction_count × 8 + lddw_count × 8 extra.

Alignment rules

Operation sizeRequired address alignment
1 byteany
2 bytes2-byte aligned
4 bytes4-byte aligned
8 bytes8-byte aligned

Misaligned access traps the runtime and aborts the transaction.

On this page

Edit on GitHub