Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The standard library

std is written entirely in BitterASM. Nothing in it is built into the compiler: bits, strings and whole instruction sets are ordinary modules you could have written yourself, and can read in the repository’s std/ directory.

Core

ModuleProvides
std.binarybits<N>, two’s-complement signed<N>, the bool type with true and false, Endian, bit_width, byte_width
std.bitfieldBit-range helpers for encoders: mask, bit, slice, field, truncate, place
std.ctypesC-style integer types: signed int8_t … int64_t and unsigned uint8_t … uint64_t
std.unsigneduint, a non-negative int
std.arrayArray<T, N> and get, updated, reversed, popped, appended, first, last, mapped, enumerate, array_from_struct
std.stringPacked String, AsciiString and Utf8String, with validation and case conversion
std.optionOption<T>
std.enumeratedEnumerated<T>, an index with a value
std.iterRange and range(start, stop, step) for stepped ranges
std.decimalDecimal and Fraction, with conversions between them and int
std.mathInteger math (pow, gcd, isqrt, popcount, …) and fixed-point math over Decimal (sqrt, ln, sin, atan2, …)

For bitter

These define the types the bitter evaluator understands. See Packing bytes with bitter.

ModuleProvides
std.bitter.deferredDeferred values, here(), span, arithmetic on them, and Positioned<N>
std.bitter.byte_orderLittleEndian<T, width>
std.bitter.layoutalign and pad_image
std.bitter.linkThe image_start and image_end labels

Executable formats

See Executables.

ModuleProvides
std.formats.elfelf64_executable, elf32_executable
std.formats.pepe64_executable
std.formats.machomacho64_executable

Architectures

Each architecture has an impl module with its registers, instruction formats and instructions, plus one or more dialects that give the instructions a syntax. Import a dialect. See Custom syntax.

ArchitectureDialects
x86-64std.x86_64.intel, std.x86_64.nasm (Intel plus NASM’s [rel label], db and friends), std.x86_64.att
RISC-V (RV32I)std.riscv.native, std.riscv.c_like (a0 = a1 + a2)
WebAssemblystd.wasm.module (modules and sections), over std.wasm.impl
PDP-10std.pdp10.impl (36-bit words, no byte order)
from std.riscv.c_like import *

a0 = a1 + a2
33 85 c5 00

The same add instruction as in Your first program, through the C-like dialect.

Reference

The std reference lists every public declaration of every module, generated from std’s doc comments by bitterasm doc. See Generating docs to do the same for your own modules.