A 24,252-byte bare-metal operating system written in pure x86-64 NASM assembly can boot straight to an interactive Qwen3-0.6B chat prompt without Linux, Windows, C, Rust, or libc. The 24 KB binary (asm-llm-os.elf) holds only the boot code, hardware drivers, and inference runtime; the 613.66 MiB Q8_0 model weights live in a separate .asmbin file loaded into physical RAM as a Multiboot module or packaged into a 661 MiB bootable ISO. Published under an MIT license in alesha-pro/llm.asm, the bare-metal OS (02-baremetal-os/) totals 4,167 lines of assembly alongside 3,857 lines of shared math, tokenizer, and transformer kernels in shared/.

Boot starts in boot.asm from Multiboot 1, zeroes .bss, builds 4-level 2 MiB huge-page identity tables covering 0 to 4 GiB (marking 0xFE000000 to 0xFFFFFFFF Strong Uncacheable for Local APIC memory-mapped I/O), and switches into 64-bit Long Mode. smp.asm parses the ACPI MADT table, wakes every CPU core via INIT-SIPI-SIPI using a trampoline at 0x8000, and coordinates threads with a lock-free spin-barrier. runtime.asm binds the .asmbin weights zero-copy from physical RAM and carves a 449 MiB KV-cache and scratch arena, while drivers.asm drives 80x25 color VGA, PS/2 keyboard input, COM1 serial, PIT/RDTSC timing, and ACPI poweroff. In QEMU KVM on an AMD EPYC 7642, cold kernel boot takes 74 to 94 milliseconds.

Inference speed comes from stripping out OS page-table overhead and specializing the matrix-vector kernel for one quantization layout. shared/matmul.asm uses a per-row split Q8_0 format (v2): each row stores K int8 weights followed by K/32 FP16 block scales, giving 64-byte-aligned row strides for 32-byte AVX2 loads. Under the default FAST_Q8=1 build, activations are quantized on the fly to int8 and multiplied with AVX2+FMA+F16C instructions (vpabsb, vpsignb, vpmaddubsw, vpmaddwd, vcvtdq2ps, vfmadd231ps) paired with next-row prefetcht0, while tokenizer.asm runs BPE merges over a pre-built 524,288-slot Fibonacci hash table.

On the same AMD EPYC 7642 (Q8_0, CPU-only -ngl 0, 34 prompt tokens, 64 generated tokens), the 14.7 KB Linux ELF (01-qwen3-inference/) beats llama.cpp by 18.0 to 35.6 percent across 1 to 40 threads, reaching 125.86 tokens per second at 40 threads. The bare-metal KVM OS adds roughly another 10 percent from 2 MiB huge pages, hitting 23.67 tok/s at 1 thread, 78.89 tok/s at 4 threads (+54 percent over llama.cpp's 51.08 tok/s), and 134.94 tok/s at 16 threads, while a 0 GB disk Proxmox VM on a 12-core Intel Xeon E5-2670 v3 reaches 55.43 tok/s decode. All outputs stay bit-exact across thread counts and match 64 of 64 greedy tokens against PyTorch FP32 (0.99965 cosine similarity), though the README notes one clear caveat: llama.cpp uses batched GEMM for prompt prefill, whereas llm.asm runs token-by-token GEMV.

Qwen3-0.6B decode speed on AMD EPYC 7642, tokens per second llama.cpp llm.asm Linux ELF llm.asm Bare-metal OS 0 35 70 105 140 1 thread 16.63 20.70 23.67 4 threads 51.08 69.24 78.89 8 threads 80.79 103.64 118.08 16 threads 103.03 121.86 134.94

Bars drawn to the repository README benchmark table on an AMD EPYC 7642 (Q8_0, 34 prompt tokens, 64 generated tokens, 3-run average). Both assembly builds outpace llama.cpp on decode across 1 to 16 threads, with the bare-metal OS gaining an extra 10 to 14 percent over the Linux binary from 2 MiB huge pages.

Running a 2B Model at Home

Scaling this assembly engine from 0.6B to a ~2B dense model (such as Qwen3-1.7B) does not require rewriting the math kernels. shared/constants.inc reads dim, hidden_dim, n_layers, n_heads, n_kv_heads, head_dim, and vocab_size dynamically from the 128-byte .asmbin header, and matmul.asm sets Q8_MAX_K to 16,384, well above a 2B model's row widths. Two boundaries in the repository still govern what fits: boot.asm only identity-maps 0 to 4 GiB (with APIC MMIO starting at 3.97 GiB) and ISO9660 Multiboot modules cap near 4 GiB, while scripts/export_weights.py reads a single model.safetensors file and assumes tied embeddings. At roughly 1.8 to 2.2 GiB for Q8_0 weights plus ~0.6 GiB for KV-cache and scratch, a 2B model lands around 2.6 GiB total and fits inside the existing 4 GiB bare-metal ceiling, whereas a 4B Q8_0 model (~4.3 GiB) overflows it.

how models fit inside the bare-metal 4 GiB identity map Q8_0 weights KV-cache and scratch arena 0 GiB 1 GiB 2 GiB 3 GiB 4 GiB APIC MMIO limit, 3.97 GiB Qwen3-0.6B (measured) 1.04 GiB total 2B target (illustrative) about 2.6 GiB total

Bars drawn to a 0 to 4 GiB physical address axis matching boot.asm's 2 MiB huge-page identity map (Local APIC MMIO begins at 3.97 GiB). Qwen3-0.6B values are the repository's 614 MiB weights and 449 MiB arena; the 2B bar is an illustrative Q8_0 budget showing why 2B fits while 4B overflows the 4 GiB map.

No GPU is needed to try a 2B build at home, and an RTX 5090 sits in a completely different problem class because llm.asm contains zero CUDA or GPU code. Every token streams weights from system RAM through CPU AVX2 registers, so the practical home PC spec is built around CPU instruction support and dual-channel memory bandwidth rather than VRAM. Any x86-64 desktop or laptop processor with AVX2, FMA, and F16C works: Intel 4th-generation Core (Haswell, 2013) or newer, or AMD Ryzen (2017) or newer, with 6 to 12 cores. Pair it with 8 GB minimum or 16 GB of RAM installed as a matched dual-channel DDR4 or DDR5 kit.

Memory bandwidth decides how fast a 2B model actually talks back on a home machine. Streaming ~2.0 to 2.2 GB per generated token over dual-channel DDR4-3200 (~35 to 45 GB/s real-world bandwidth) yields roughly 15 to 20 tokens per second, while dual-channel DDR5-6000 (~65 to 85 GB/s real-world) reaches roughly 25 to 35 tokens per second. Long prompts still pause longer than in llama.cpp because prefill is unbatched GEMV.

For home testing, the 14.7 KB Linux ELF or a QEMU KVM / VirtualBox VM is far simpler than booting raw USB bare metal. Because drivers.asm only supports PS/2 keyboards and legacy 80x25 VGA text mode, a modern PC without a PS/2 port or BIOS USB-to-PS/2 legacy emulation can boot the kernel without accepting keystrokes.