Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

os: derive the boot banner model name from the loaded .asmbin

Kevin Griffin5d15e17d1ec0
diff --git a/02-baremetal-os/kernel.asm b/02-baremetal-os/kernel.asm
index a64362d..0330466 100644
--- a/02-baremetal-os/kernel.asm
+++ b/02-baremetal-os/kernel.asm
@@ -165,7 +165,7 @@ kernel_main:
call smp_init
mov [rel g_active_cores], rax
- ; 5. Bind Qwen3-0.6B model zero-copy & allocate KV-cache / scratch arena
+ ; 5. Bind Qwen3 model zero-copy & allocate KV-cache / scratch arena
mov rdi, r13 ; mod_start
mov rsi, r15 ; mod_size
mov rdx, [rel opt_ctx_len] ; max_seq_override
@@ -423,7 +423,7 @@ kernel_main:
; ============================================================================
; void run_inference(const char *prompt in rdi, int show_boot_ttft in esi)
-; Exact same Qwen3-0.6B BPE + prefill + streaming decode loop as Phase 1!
+; Exact same Qwen3 BPE + prefill + streaming decode loop as Phase 1!
; ============================================================================
run_inference:
push rbx
@@ -821,7 +821,11 @@ print_boot_banner:
mov dil, VGA_ATTR_WHITE
call vga_set_color
mov edi, 1
- lea rsi, [rel ban_title]
+ lea rsi, [rel ban_title_pre]
+ call write_cstr
+ call print_model_name
+ mov edi, 1
+ lea rsi, [rel ban_title_post]
call write_cstr
mov dil, VGA_ATTR_CYAN
@@ -915,8 +919,9 @@ print_boot_banner:
call write_cstr
mov dil, VGA_ATTR_WHITE
call vga_set_color
+ call print_model_name
mov edi, 1
- lea rsi, [rel ban_qwen]
+ lea rsi, [rel ban_q8]
call write_cstr
mov rax, [rel g_mod_size]
add rax, 524288
@@ -932,6 +937,13 @@ print_boot_banner:
mov dil, VGA_ATTR_GREY
call vga_set_color
mov edi, 1
+ lea rsi, [rel ban_mod_lyr]
+ call write_cstr
+ lea rax, [rel g_ctx]
+ mov edi, 1
+ mov rsi, [rax + CTX_N_LAYERS]
+ call write_u64
+ mov edi, 1
lea rsi, [rel ban_mod_ctx]
call write_cstr
lea rax, [rel g_ctx]
@@ -953,6 +965,93 @@ print_boot_banner:
pop rbx
ret
+; ----------------------------------------------------------------------------
+; print_model_name — emit "Qwen3-<size>B" from the loaded .asmbin header.
+; .asmbin has no GGUF general.name / general.size_label, so the size label is
+; computed from vocab, dim, n_layers, head/KV dims and the Q8_0 Qwen3 layout
+; (tied embeddings, QK-Norm, SwiGLU) and rounded to tenths of a billion.
+; ----------------------------------------------------------------------------
+print_model_name:
+ push rbx
+ push r12
+ sub rsp, 8 ; 16-byte align + 3-byte print buf
+
+ lea rbx, [rel g_ctx]
+
+ ; P_emb = vocab * dim (tied: no separate LM head)
+ mov rax, [rbx + CTX_VOCAB_SIZE]
+ imul rax, [rbx + CTX_DIM]
+
+ ; per layer: Q+O + K+V + SwiGLU + 2x RMSNorm + q_norm/k_norm
+ mov rcx, [rbx + CTX_DIM]
+ imul rcx, [rbx + CTX_Q_DIM]
+ add rcx, rcx ; Q proj + O proj
+
+ mov rdx, [rbx + CTX_DIM]
+ imul rdx, [rbx + CTX_KV_DIM]
+ add rdx, rdx ; K proj + V proj
+ add rcx, rdx
+
+ mov rdx, [rbx + CTX_DIM]
+ imul rdx, [rbx + CTX_HIDDEN_DIM]
+ lea rdx, [rdx + rdx*2] ; 3 * dim * hidden (gate/up/down)
+ add rcx, rdx
+
+ mov rdx, [rbx + CTX_DIM]
+ add rdx, rdx ; attn + mlp RMSNorm
+ add rcx, rdx
+
+ mov rdx, [rbx + CTX_HEAD_DIM]
+ add rdx, rdx ; q_norm + k_norm
+ add rcx, rdx
+
+ imul rcx, [rbx + CTX_N_LAYERS]
+ add rax, rcx
+ add rax, [rbx + CTX_DIM] ; final RMSNorm
+
+ ; tenths of a billion, rounded: (P + 50_000_000) / 100_000_000
+ mov rcx, 100000000
+ add rax, 50000000
+ xor edx, edx
+ div rcx
+ mov r12, rax ; tenths
+
+ mov edi, 1
+ lea rsi, [rel ban_qwen3]
+ call write_cstr
+
+ mov rax, r12
+ xor edx, edx
+ mov ecx, 10
+ div ecx ; rax = integer B, edx = tenths digit
+ mov r12d, edx
+
+ mov edi, 1
+ mov rsi, rax
+ call write_u64
+
+ test r12d, r12d
+ jz .unit
+ mov byte [rsp], '.'
+ mov eax, r12d
+ add al, '0'
+ mov [rsp + 1], al
+ mov byte [rsp + 2], 0
+ mov edi, 1
+ mov rsi, rsp
+ call write_cstr
+.unit:
+ mov byte [rsp], 'B'
+ mov byte [rsp + 1], 0
+ mov edi, 1
+ mov rsi, rsp
+ call write_cstr
+
+ add rsp, 8
+ pop r12
+ pop rbx
+ ret
+
; ============================================================================
; CPUID Brand String Reader (leaves 0x80000002..0x80000004 -> g_cpu_brand)
; ============================================================================
@@ -1291,7 +1390,8 @@ d_1e6: dq 1000000.0
d_1e9: dq 1000000000.0
ban_line: db "==============================================================================", 10, 0
-ban_title: db " asm-llm OS v2.0 | Bare-Metal Qwen3-0.6B in 100% Pure x86-64 Assembly", 10, 0
+ban_title_pre: db " asm-llm OS v2.0 | Bare-Metal ", 0
+ban_title_post: db " in 100% Pure x86-64 Assembly", 10, 0
ban_cpu: db " CPU : ", 0
ban_avx_tsc: db " (AVX2+FMA, ", 0
ban_mhz_nl: db " MHz)", 10, 0
@@ -1301,9 +1401,11 @@ ban_ram: db " RAM : ", 0
ban_ram_mid: db " MiB | Arena: ", 0
ban_boot_lbl: db " MiB | Boot: ", 0
ban_model: db " Model : ", 0
-ban_qwen: db "Qwen3-0.6B Q8_0 (", 0
+ban_qwen3: db "Qwen3-", 0
+ban_q8: db " Q8_0 (", 0
ban_mod_at: db " MiB @ 0x", 0
-ban_mod_ctx: db ", 28L, ctx=", 0
+ban_mod_lyr: db ", ", 0
+ban_mod_ctx: db "L, ctx=", 0
msg_prompt_lbl: db "Prompt: ", 0
msg_repl_help: db "Interactive Bare-Metal Chat (/clear, /think, /nothink, /bench, /halt, /help)", 10, 0
diff --git a/scripts/mkiso.sh b/scripts/mkiso.sh
index d25047f..ce0d010 100755
--- a/scripts/mkiso.sh
+++ b/scripts/mkiso.sh
@@ -41,7 +41,7 @@ terminal_output console serial
set timeout=0
set default=0
-menuentry "asm-llm OS v2.0 (Bare-Metal Qwen3-0.6B in Pure x86-64 Assembly)" {
+menuentry "asm-llm OS v2.0 (Bare-Metal Qwen3 in Pure x86-64 Assembly)" {
multiboot /boot/asm-llm-os.elf ${CMDLINE}
module /boot/model.asmbin
boot