A high-level assembly-oriented language with bare-metal x86-64 performance. Inline NASM. JIT compilation. FFI. All in one coherent source file.
01 — About
CDNEE (Control Dynamic Native Execution Engine) is a high-level assembly-oriented programming language designed for direct access to native machine-code execution without the complexity of traditional assemblers or low-level compilers. It sits at a unique intersection: readable, structured syntax on the surface, bare-metal native performance underneath.
Programs are written in .cdnee source files and run through the CDNEE runtime, which compiles and executes x86-64 machine code on the fly using a built-in JIT engine backed by NASM. You can drop into raw assembly, benchmark it, patch it at runtime, inspect its disassembly, snapshot its memory, and call foreign libraries — all from a single coherent source file.
02 — Language Tiers
CDNEE is organized into three execution tiers. Tier 1 requires no compilation step and is available immediately in any program. Tier 2 gives you the full JIT/MEX engine. Tier 3 targets bare-metal OS development — flat binaries and freestanding ELF64 kernels.
03 — Language Syntax
CDNEE source files are plain UTF-8 text with the .cdnee extension. One statement per line, no semicolons needed. Comments start with ; or #. Execution begins at the @entry label.
; hello.cdnee @entry main main: PRINTLN "Hello, CDNEE!" EXIT
SET x, 42 LET name, "Alice" SET pi, 3.14159 SET flag, TRUE ADD result, x, 100 ; result = 142 MUL sq, x, x ; sq = 1764 MOD rem, x, 5 ; rem = 2 PRINTLN result
SET i, 1 loop: CMP i, 10 JGT done PRINTLN i ADD i, i, 1 JMP loop done: EXIT
FUNC square, n: MUL r, n, n RETURN r END main: SET result, CALL square, 9 PRINTLN result ; → 81 EXIT
TRY: SET r, CALL risky_fn, 42 CATCH err: PRINT "Error: " PRINTLN err END
JIT_COMPILE_INLINE """ BITS 64 mov rax, rdi imul rax, rdi ret """, tag=sq SET result, CALL sq, 9 ; → 81 PRINTLN result
| Opcode | Syntax | Condition |
|---|---|---|
| JE | JE label | Jump if left == right (after CMP) |
| JNE | JNE label | Jump if left != right |
| JLT | JLT label | Jump if left < right |
| JGT | JGT label | Jump if left > right |
| JLE | JLE label | Jump if left <= right |
| JGE | JGE label | Jump if left >= right |
| JMP | JMP label | Unconditional jump |
These variables are automatically set by the runtime after certain operations:
| Variable | Set By |
|---|---|
| _last_offset | FIND |
| _found_offset | BIN_SEARCH, LIN_SEARCH |
| _checksum | CHECKSUM |
| _disasm | DISASM (when captured) |
| _dump | DUMP (when captured) |
| _bench_mean | BENCHMARK |
| _bench_min | BENCHMARK |
| _asm_size | ASM_SIZEOF |
| _reverted | PATCH_REVERT |
| _profile_ms | PROFILE_END |
04 — Standard Library
All Tier-1 operations run via the DNEE native engine when available, or fall back to pure Python. Every operation stores its result in the dest variable. No compilation step required.
@entry main main: ; Primality and number theory IS_PRIME p, 97 ; p = 1 NEXT_PRIME q, 100 ; q = 101 TOTIENT t, 12 ; t = 4 ; Safe arithmetic with overflow detection SAFE_MUL r, 999999999, 999999999, ov CMP ov, 1 JE overflow_handler ; Cycle-accurate timing RDTSC_START t0 FIBONACCI f, 40 RDTSC_STOP t1 SUB cycles, t1, t0 PRINT "Fib(40)=" PRINT f PRINT " cycles=" PRINTLN cycles EXIT overflow_handler: PRINTLN "Overflow detected!" EXIT
05 — JIT & MEX Engine
Tier-2 gives you the full Machine Execution Engine (MEX). Compile inline NASM or .asm files into executable memory, benchmark them, patch them live, snapshot and restore, export to disk, and reload across sessions.
JIT functions require explicit type annotations to build the correct ctypes.CFUNCTYPE. Multiple arguments use colon-separated types.
JIT_COMPILE / JIT_COMPILE_INLINE
Assemble a .asm file or triple-quoted inline block into an executable memory region tagged with a name. Specify argtypes and rettype for the correct calling convention. Use overwrite=true to replace an existing region.
JIT_COMPILE_MANY / JIT_COUNTED / JIT_FN
Compile multiple assembly files in one call with JIT_COMPILE_MANY. JIT_COUNTED and JIT_FN wrap the compiled function with a call counter, accessible via CALL_STATS for profiling.
EXPORT_BIN / IMPORT_BIN / CALL_BIN / BIN_CONTEXT
Serialize compiled JIT regions to disk as .bin files and reload them in future sessions — bypassing assembly overhead. CALL_BIN imports and calls in one step. BIN_CONTEXT scopes the lifetime to a block.
FREEZE / THAW / SNAPSHOT / RESTORE / CLONE / COPY_ON_WRITE
Control the mutability and lifecycle of JIT regions. FREEZE prevents further patching. SNAPSHOT saves the current bytes; RESTORE reverts. CLONE duplicates a region. COPY_ON_WRITE creates a copy with specific bytes changed.
PATCH_NOP / PATCH_INT64 / PATCH_FILL / PATCH_REPLACE / PATCH_BYTES
Overwrite bytes in live JIT regions. All patch operations are recorded in a patch history. Use PATCH_REVERT to undo N steps or PATCH_REVERT_ALL to restore the original. TRAMPOLINE inserts a jump redirect at an offset.
DISASM / DUMP / FIND / CHECKSUM / REGION_INFO / PATCH_HISTORY
Inspect live JIT regions. Disassemble bytes, hex-dump, search for byte patterns, compute CRC-32 checksums, view region address/size/permissions, and walk the full patch history.
BENCHMARK / PROFILE_BLOCK / JIT_STATS / CACHE_STATS
BENCHMARK runs a function with warmup and timed iterations, reporting mean/min/max/stddev. PROFILE_BLOCK is a scoped timer. CACHE_WARM, CACHE_CLEAR, and CACHE_INVALIDATE manage the JIT code cache.
@entry main main: ; Compile inline NASM with typed signature JIT_COMPILE_INLINE """ BITS 64 mov rax, rdi imul rax, rsi ret """, tag=mul, argtypes=i64:i64, rettype=i64 SET r, CALL mul, 6, 7 PRINTLN r ; → 42 ; Benchmark it BENCHMARK mul, 6, 7, iterations=1000000, warmup=100 ; Snapshot and inspect SNAPSHOT mul SET r_, DISASM mul, 32 CHECKSUM mul PRINTLN _checksum ; NOP the imul instruction (bytes 3-9) PATCH_NOP mul, 3, 4 ; Revert the patch PATCH_REVERT mul, 1 ; Export for future use EXPORT_BIN "./cache" JIT_RELEASE mul EXIT
06 — Foreign Function Interface
The CDNEE FFI has two complementary halves: EXTERN file imports (.cdneef header files that add pure-CDNEE functions) and native symbol bindings (shared libraries loaded via ctypes).
; Import a function header EXTERN "math_utils.cdneef" ; Namespace prefix to avoid collisions EXTERN "vec2.cdneef", alias_prefix=v2_ EXTERN "vec3.cdneef", alias_prefix=v3_ SET r, CALL v2_add, 10, 20 SET r, CALL v3_add, 1, 2, 3
; Bind libm sqrt EXTERN_FUNC "m", func=sqrt, alias=fsqrt, argtypes=f64, rettype=f64 SET r, CALL fsqrt, 144.0 PRINTLN r ; → 12.0 ; Windows API — stdcall EXTERN "kernel32", func=Sleep, alias=sleep_ms, argtypes=u32, rettype=void, cdecl=false
@entry main EXTERN_FUNC "c", func=abs, alias=iabs, argtypes=i32, rettype=i32 EXTERN_FUNC "m", func=pow, alias=fpow, argtypes=f64:f64, rettype=f64 main: SET a, CALL iabs, -123 PRINTLN a ; → 123 SET b, CALL fpow, 3.0, 8.0 PRINTLN b ; → 6561.0 EXIT
07 — CLI & Compiler
CDNEE ships two command-line tools: CDNEE (the interpreter / REPL) and CDNEE-CC (the ahead-of-time compiler). Both are installed alongside the package.
usage: CDNEE [OPTIONS] [file.cdnee]
usage: CDNEE-CC [OPTIONS] [source.cdnee]
# Standard modes CDNEE-CC program.cdnee # compile to .so/.dll CDNEE-CC program.cdnee -o dist/ # output to dist/ CDNEE-CC program.cdnee --asm-only # emit NASM only CDNEE-CC program.cdnee --show-asm # print NASM to stdout CDNEE-CC program.cdnee --load-test # compile + ctypes smoke-test CDNEE-CC program.cdnee --list-exports # show exported symbols CDNEE-CC program.cdnee --exe # compile to executable CDNEE-CC program.cdnee --exe --run # compile + run immediately CDNEE-CC program.cdnee --opt 2 # peephole + strength reduction # OS / flat-binary modes (v2.4) CDNEE-CC boot.cdnee --flat # MBR / flat binary CDNEE-CC kernel.cdnee --os # freestanding ELF64 kernel CDNEE-CC kernel.cdnee --os --load-addr 1M # load at 1 MiB CDNEE-CC kernel.cdnee --os --ld-script k.ld # custom linker script CDNEE-CC boot.cdnee --flat --qemu # flat binary + QEMU CDNEE-CC kernel.cdnee --os --qemu # kernel + QEMU -kernel
$ CDNEE --repl DNEE> RUN program.cdnee DNEE> EXEC SET x, 42 DNEE> EXEC PRINTLN x DNEE> DISASM sq DNEE> DUMP sq DNEE> JIT_STATS DNEE> CACHE_STATS DNEE> REGION_INFO sq DNEE> BENCHMARK sq 9 iterations=500000 DNEE> VARS DNEE> HELP DNEE> EXIT
08 — OS Development (v2.4)
CDNEE v2.4 adds a complete OS-development tier. Write bootloaders, kernels, and bare-metal programs using high-level OS opcodes that compile to flat binaries or freestanding ELF64. The same source runs in the interpreter's simulation mode for unit-testing OS logic without QEMU.
CDNEE-CC boot.cdnee --flatqemu-system-i386 -drive format=raw,file=boot.binCDNEE-CC kernel.cdnee --osqemu-system-x86_64 -kernel kernel.elf--ld-script; Minimal x86 real-mode MBR ; Prints "Hi OS!" via BIOS int 0x10 OS_BITS 16 OS_ORG 0x7C00 OS_CLI OS_STI JIT_COMPILE_INLINE greet_bios """ mov si, msg .loop: lodsb or al, al jz .done mov ah, 0x0E int 0x10 jmp .loop .done: hlt msg: db "Hi OS!", 13, 10, 0 """ tag=greet_bios CALL greet_bios, 0 OS_HLT OS_BOOT_SIG ; pad + 0xAA55
; Freestanding 64-bit kernel OS_BITS 64 OS_MULTIBOOT 0x00000003 OS_GLOBAL kernel_start kernel_start: OS_CLI OS_VGA_CLEAR 0x0F ; white on black OS_VGA_PUTS 0, 0, "CDNEE Kernel v2.4", 0x0F OS_SERIAL_INIT 0x3F8, 115200 OS_SERIAL_PUTS 0x3F8, "Kernel alive\r\n" OS_HLT
--os-sim --os-vga to test OS logic without QEMU. Inspect interp._os_state for VGA buffer, serial log, and memory allocator state.
Section / Layout
| Opcode | Syntax | Description |
|---|---|---|
| OS_BITS | OS_BITS 16|32|64 | Set NASM instruction width — must be first in flat sources |
| OS_ORG | OS_ORG addr | Set origin address (NASM ORG). 0x7C00 for MBR, 0x0100 for COM. |
| OS_SECTION | OS_SECTION ".text" | Switch assembly section (OS mode only; no-op in flat) |
| OS_GLOBAL | OS_GLOBAL sym | Export symbol (NASM global directive) |
| OS_ALIGN | OS_ALIGN n [, fill] | Align to power-of-two boundary, fill gaps (default 0x00) |
| OS_TIMES | OS_TIMES count, byte | NASM TIMES directive — repeat byte value count times |
| OS_BOOT_SIG | OS_BOOT_SIG | Pad to 510 bytes + emit 0xAA55 boot signature. Must be last in MBR. |
| OS_MULTIBOOT | OS_MULTIBOOT [flags] | Emit Multiboot 1 header (magic + flags + checksum) for GRUB |
CPU Control & Interrupts
| Opcode | Syntax | Description |
|---|---|---|
| OS_CLI | OS_CLI | Clear interrupt flag (disable hardware IRQs) |
| OS_STI | OS_STI | Set interrupt flag (enable hardware IRQs) |
| OS_HLT | OS_HLT | Halt until next interrupt — generates hlt in a loop |
| OS_NOP | OS_NOP | Emit a single NOP instruction (timing padding) |
| OS_IRET | OS_IRET [bits] | Interrupt return — iretq (64-bit) or iret (16/32-bit) |
| OS_RING | OS_RING 0|3 | Declare privilege ring for documentation/codegen hints |
| OS_SET_ISR | OS_SET_ISR vector, handler | Dynamically patch running IDT entry at vector to handler |
Hardware I/O & VGA & Serial
| Opcode | Syntax | Description |
|---|---|---|
| OS_OUTB | OS_OUTB port, val | Write byte to x86 I/O port |
| OS_OUTW | OS_OUTW port, val | Write word to x86 I/O port |
| OS_INB | OS_INB dest, port | Read byte from I/O port into variable |
| OS_INW | OS_INW dest, port | Read word from I/O port into variable |
| OS_VGA_CLEAR | OS_VGA_CLEAR [attr] | Fill 80×25 VGA text screen with spaces and attribute byte |
| OS_VGA_PUTC | OS_VGA_PUTC col, row, char, attr | Write one character at (col, row) with attribute |
| OS_VGA_PUTS | OS_VGA_PUTS col, row, str, attr | Write NUL-terminated string starting at (col, row) |
| OS_SERIAL_INIT | OS_SERIAL_INIT port, baud | Initialise 16550-compatible UART at I/O port |
| OS_SERIAL_PUTC | OS_SERIAL_PUTC port, char | Transmit one byte — blocks until TX FIFO has space |
| OS_SERIAL_PUTS | OS_SERIAL_PUTS port, str | Transmit a NUL-terminated string |
Descriptor Tables, Paging & Memory
| Opcode | Syntax | Description |
|---|---|---|
| OS_GDT_ENTRY | OS_GDT_ENTRY base, limit, access, flags | Emit 8-byte GDT segment descriptor inline |
| OS_IDT_ENTRY | OS_IDT_ENTRY offset, selector, type_attr | Emit 8-byte IDT gate descriptor |
| OS_LGDT | OS_LGDT gdtr_label | Load GDT register |
| OS_LIDT | OS_LIDT idtr_label | Load IDT register |
| OS_MAP_PAGE | OS_MAP_PAGE virt, phys, flags | Map one 4 KiB page (flags: 0x1=present, 0x2=write, 0x4=user) |
| OS_UNMAP_PAGE | OS_UNMAP_PAGE virt | Unmap page and flush TLB entry (INVLPG) |
| OS_PHYS_ALLOC | OS_PHYS_ALLOC dest, pages | Simulate allocating pages consecutive 4 KiB frames |
| OS_PHYS_FREE | OS_PHYS_FREE addr, pages | Release physical frames |
Raw Data Directives
| Opcode | Syntax | Description |
|---|---|---|
| OS_DB | OS_DB b1 [, b2, ...] | Emit byte(s) — strings supported: OS_DB "Hello", 0 |
| OS_DW | OS_DW w1 [, w2, ...] | Emit 16-bit little-endian word(s) |
| OS_DD | OS_DD d1 [, d2, ...] | Emit 32-bit dword(s) |
| OS_DQ | OS_DQ q1 [, q2, ...] | Emit 64-bit qword(s) — supports label references |
# ── Flat binary (MBR bootloader) ──────────────────────────────────── CDNEE-CC hello_mbr.cdnee --flat # Produces hello_mbr.bin — exactly 512 bytes qemu-system-i386 -drive format=raw,file=hello_mbr.bin -nographic qemu-system-i386 -drive format=raw,file=hello_mbr.bin -serial stdio # ── ELF64 kernel (Multiboot) ───────────────────────────────────────── CDNEE-CC kernel.cdnee --os --load-addr 0x100000 # Produces kernel.elf — boot with GRUB or QEMU -kernel qemu-system-x86_64 -kernel kernel.elf -serial stdio -nographic # ── Inspection ──────────────────────────────────────────────────────── xxd hello_mbr.bin | tail -2 # check boot signature 55 AA ndisasm -b 16 hello_mbr.bin | head -40 # disassemble MBR readelf -S kernel.elf # ELF sections objdump -d kernel.elf | head -80 # disassemble .text # ── Interpreter simulation (no QEMU needed) ─────────────────────────── CDNEE --os-sim --os-vga --os-state kernel.cdnee
09 — File Types
CDNEE uses four file types that interoperate cleanly across the toolchain.
.cdnee
CDNEE source program. Plain UTF-8 text. Entry point declared with @entry or defaults to the top of the file. Executed by DNEE_CLI or the Python API.
.cdneef
CDNEE function definition file. Contains only FUNC definitions and optional EXTERN imports. Imported into programs with EXTERN. Supports alias_prefix for namespacing.
.asm
NASM assembly source loaded by JIT_COMPILE. Must begin with BITS 64 for x86-64 code. Uses System V AMD64 calling convention by default.
.bin
Exported compiled binary region. Written by EXPORT_BIN, loaded by IMPORT_BIN or CALL_BIN. Bypasses the assembly step on subsequent runs — ready to execute directly.
10 — Version History
CDNEE has evolved rapidly since its initial release. Each version adds significant capabilities to the execution engine and language surface.
| Version | Notable Changes |
|---|---|
| v1.0 | OS development tier — CDNEE-CC compiler with --flat (MBR/COM) and --os (ELF64 kernel) modes; OS opcodes (OS_BITS, OS_ORG, OS_VGA_*, OS_SERIAL_*, OS_GDT_ENTRY, OS_IDT_ENTRY, OS_MAP_PAGE, OS_PHYS_ALLOC, OS_DB/DW/DD/DQ, OS_BOOT_SIG, OS_MULTIBOOT); QEMU integration; interpreter simulation mode (--os-sim, --os-state, --os-vga, --os-image) |
| v1.0 | ExternFileNode, ExternSymNode, ExternLibNode; CDNEE_CTYPES_MAP; _source_dir resolution; full FFI guide with .cdneef header imports and alias_prefix namespacing |
| v1.0 | Dot-label support (.name:) following NASM/GAS convention; Lexer fixes FIX-1 through FIX-5; keyword label-peek disambiguation |
| v1.0 | JitCompileNode argtypes/rettype fields; DneeCallNode; full type system with i8/u8/i16/u16/i32/u32/i64/u64/f32/f64/ptr/bool/void |
| v1.0 | Tier-2 JIT/MEX engine; binary export/import (EXPORT_BIN, IMPORT_BIN, CALL_BIN, BIN_CONTEXT); memory operations (FREEZE, THAW, SNAPSHOT, RESTORE, CLONE, COPY_ON_WRITE, TRAMPOLINE); hot patching; profiling and stats |
| v1.0 | Tier-1 math library (50+ native ops), control flow (CMP/JE/JNE/JLT/JGT/JLE/JGE/JMP), functions (FUNC/CALL/RETURN), error handling (TRY/CATCH/END), basic I/O |