Skip to main content

uc80 - ANSI C Compiler for Z80

A C compiler targeting the Z80 processor and CP/M operating system. Produces assembly compatible with the um80 assembler and linker toolchain.

Installation

pip install uc80

Or from source:

pip install -e .

Requires the um80 assembler/linker toolchain:

pip install um80

Quick Start

# Compile, assemble, and link a C program
LIB=$(uc80 --print-lib-dir)
uc80 hello.c -o hello.mac
um80 hello.mac -o hello.rel
ul80 hello.rel $LIB/libc.lib $LIB/runtime.lib -o hello.com

uc80 --print-lib-dir prints the library directory. In a git checkout, run uc80 --build-libs once first. Details are in docs/libraries.md.

For the smallest binaries, compile all .c files in one invocation, so uc80 can optimize the whole program. Separate compilation needs --no-whole-program and crt0.rel; see docs/compiler_options.md.

Features

  • ANSI C (C11/C23) with most standard features
  • Z80 code generation with peephole optimization
  • IEEE 754 single-precision float
  • Configurable integer sizes (--int=16|32, --long=32|64); default is 16-bit int, 32-bit long, 64-bit long long
  • Structs, unions, bitfields, enums
  • Full preprocessor (#include, #define, #if, #pragma, etc.)
  • Modular library with selective linking
  • Whole-program optimization
  • Basic inline assembly (asm("...")), emitted verbatim and never optimized
  • CP/M console line endings (CR LF by default, --no-crlf for raw LF)
  • CP/M target with embedded crt0
  • Libraries ship in the wheel and are discoverable (uc80 --print-lib-dir, uc80.lib_dir())

Binary Size and Tests

uc80 produces the smallest known binaries for Z80/CP/M among current compilers. On the Fujitsu compiler-test-suite, uc80 output is less than half the size of z88dk output. uc80 passes 220 of the 220 c-testsuite tests. Numbers are in docs/benchmarks.md.

Documentation

  • Finding the libraries - --print-lib-dir, --build-libs, UC80_LIB_DIR
  • Compiler options - whole-program optimization, --printf, CR LF line endings, --int/--long, separate compilation
  • Calling convention - register and stack convention, which functions qualify, --no-register-cc
  • Register locals - up to four byte locals (or two words) of a function live in B, C, D and E, and one pointer lives in IY, --no-register-locals
  • Address CSE - the compiler computes a repeated array element address once, a = b = K stores K to each target, --no-addr-cse, --no-chain-store
  • Dead locals - the compiler removes a local that nothing reads, and a store that a later store overwrites, --no-dead-store
  • Inline block operations - memset and memcpy with a constant size become LDIR or LDI code, --no-blockops
  • Pair peephole rules - a discarded comma computes no value, copies between BC, DE and HL go away, --no-discard-comma, --no-peep-pairs
  • Loop-invariant code motion - an integer expression that a loop does not change is computed before the loop, --no-licm
  • Value ranges - a counter in 0 to 32767 uses the short unsigned compare, --no-range-cmp
  • Index narrowing - a 32-bit array index is computed in 16 bits, --no-narrow-index
  • Family J passes - fast BSS clear, putchar statements, loop rotation, fill loops, parameters in registers, loads out of loops, byte registers, and more: one page for each, one --no- switch for each
  • Family K step 1 - less library code in the linked image: printf("\n"), 32-bit and 16-bit divide, qsort of a few elements, one --no- switch for each
  • Family L step LA - a static pointer to one object becomes a fixed address, a word qsort with a register comparator, no call of an empty function, one divide for x / y and x % y, one --no- switch for each
  • Family L step LB - external functions in registers (#pragma uc80 regcall), a char result in L, cheaper compares of register locals, smaller ROM kernels
  • Family K step 2 - smaller generated code: counted for loops, if/else arms, a liveness pass, divide and puts routines, one --no- switch for each
  • Inline assembly - asm("...") rules and limits
  • Volatile objects - every volatile access happens as written, and how each pass keeps that
  • Debug markers - -g writes source line markers for a debugger, and the code stays the same
  • optnone - --optnone, #pragma uc80 optnone and [[uc80::optnone]] keep one function unoptimized for a debugger
  • Binary size and test results - speed and size against 8 compilers, and external test suite pass rates
  • C standard compliance - implemented and missing C features
  • Compile time - why long expressions and large programs compiled slowly, and the repairs
  • Build a Z80 ROM - --target=rom, crt0, vectors, ul80 ROM link, libc_rom.lib, limits
  • Interrupt functions and hardware access - #pragma uc80 interrupt, <z80.h> port I/O, critical sections, __at, SDCC __interrupt and __sfr
  • Neo Geo sound driver example - NMI command, timer IRQ, YM busy wait and bank select in one C file
  • ROM test runner - run a Z80 ROM, log port I/O and T-states, inject IRQ and NMI
  • Types and conversions - enumeration types, tags in blocks, bit-field assignment, float and integer conversions
  • Float status - IEEE 754 single-precision support
  • printf, program exit and files, console output - conversions and limits, atexit, fopen modes, ftell and fseek, TAB
  • Math library, scanf and strtol, library modules in C, float interpreter - accuracy, limits, how the modules are made
  • CHANGELOG - release history
  • 80un - Unpacker for the CP/M archive and compression formats LBR, ARC, squeeze, crunch, and CrLZH.
  • cpmdroid - Z80/CP/M emulator for Android phones and tablets. It emulates the RomWBW HBIOS interface and a VT100 terminal.
  • cpmemu - Z80/CP/M emulator for Linux and Windows, with Z80 and 8080 CPU cores. It translates the BDOS and BIOS calls of CP/M 2.2 programs to the host file system.
  • ioscpm - Z80/CP/M emulator for iOS and macOS. It emulates the RomWBW HBIOS interface and runs CP/M 2.2 and CP/M 3.
  • learn-ada-z80 - Collection of more than 90 Ada example programs for uada80, the Ada compiler for the Z80 processor and CP/M.
  • mbasic - Python interpreter for MBASIC 5.21, the Microsoft BASIC-80 for CP/M. Two compiler backends compile the programs to CP/M .COM files or to JavaScript.
  • mbasic2025 - Reconstruction of the lost source code of MBASIC 5.21, the Microsoft BASIC-80 for CP/M. The MACRO-80 source code assembles to a binary that matches mbasic.com byte for byte.
  • mbasicc - C++17 interpreter for MBASIC 5.21, the Microsoft BASIC-80 for CP/M. It runs on Linux and macOS.
  • mbasicc_web - Web browser interpreter for MBASIC 5.21, the Microsoft BASIC-80 for CP/M. Emscripten compiles the mbasicc interpreter to WebAssembly.
  • mpm2 - Z80 emulator for MP/M II, the multi-user CP/M operating system. Users connect over SSH, and SFTP clients transfer files.
  • romwbw_emu - Hardware-level Z80/CP/M emulator for Linux and macOS. It emulates the RomWBW HBIOS interface and switches banks in 512 KB of ROM and 512 KB of RAM.
  • scelbal - Floating-point BASIC interpreter for the 8080 processor and CP/M. A translator converts the original 8008 source code to 8080 source code.
  • uada80 - Ada compiler for the Z80 processor and CP/M 2.2. It compiles a subset of Ada 2012 to CP/M .COM files.
  • uc386 - C23 compiler for the i386 processor and MS-DOS. This sibling backend shares the uc_core frontend.
  • uc_core - Shared C23 frontend and AST optimizer for the uc80 and uc386 compilers.
  • ucow - Cowgol compiler for the Z80 processor and CP/M. It runs on Linux in Python.
  • um80_and_friends - Linux toolchain that is compatible with Microsoft MACRO-80. It has an assembler, a linker, a librarian, and a disassembler.
  • upeepz80 - Peephole optimizer for Z80 compilers. It shortens jumps to jr, builds djnz loops, and removes dead stores.
  • uplm80 - PL/M-80 compiler for the Z80 processor and CP/M. It writes Intel 8080 and Zilog Z80 assembly language.
  • uplox - LR(1) and GLR parser generator. It writes the lexer and parser tables for the C23 frontend of uc_core from examples/c23.uplox.
  • z80cpmw - Z80/CP/M emulator for Windows. It emulates the RomWBW HBIOS interface and boots CP/M from disk images.

License

GPL-3.0-or-later. See LICENSE.

Metadata

Release files for uc80 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uc80 0.8.0
File Size Uploaded Provenance Actions
uc80-0.8.0.tar.gz 1.5 MB With provenance Details for uc80-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uc80 0.8.0
File Interpreter ABI Platform Actions
uc80-0.8.0-py3-none-any.whl Python 3 none any Details for uc80-0.8.0-py3-none-any.whl

Total release size: 3.0 MB

Release files / uc80-0.8.0.tar.gz

Download URL uc80-0.8.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
ec2f20296c97cbe8108d978cde0fa56571aa9503395b82cefa160fcd9499edca
BLAKE2b-256 checksum
How to use checksums
a864ef094837b3ec13f67ee7f7980de0e853caa19cab26e882837264db23616e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / uc80-0.8.0-py3-none-any.whl

Download URL uc80-0.8.0-py3-none-any.whl
Size 1.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
78429a4c29a08e1a31491c9af98ff9fe5a6b54b6bc8f1aebd83b5ba0b0103201
BLAKE2b-256 checksum
How to use checksums
4bb929ae59908f5e3d714fe98266546b4eff711a254cab5971793a31eecbe82a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for uc80 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for uc80-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page