Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

sectorc

> 编程语言
Open source

A C Compiler that fits in the 512 byte boot sector of an x86 machine

1.8K stars0 likes1 views
WebsiteGitHub

About

A C Compiler that fits in the 512 byte boot sector of an x86 machine

SectorC

SectorC is a C compiler written in x86-16 assembly that fits within the 512 byte boot sector of an x86 machine. It supports a subset of C that is large enough to write real and interesting programs. It is quite likely the smallest C compiler ever written.

In a base64 encoding, it looks like this:

…

Supported language

A fairly large subset is supported: global variables, functions, if statements, while statements, lots of operators, pointer dereference, inline machine-code, comments, etc. All of these features make it quite capable.

For example, the following program animates a moving sine-wave:

…

Screenshot

Provided Example Code

A few examples are provided that leverage the unique hardware aspects of the x86-16 IBM PC:

  • examples/hello.c: Print a text greeting on the screen writing to memory at 0xB8000
  • examples/sinwave.c: Draw a moving sine wave animation with VGA Mode 0x13 using an appropriately bad approximation of sin(x)
  • examples/twinkle.c: Play “Twinkle Twinkle Little Star” through the PC Speaker (Warning: LOUD)

Grammar

The following grammar is accepted and compiled by sectorc:

…

In addition, both // comment and /* multi-line comment */ styles are supported.

(NOTE: This grammar is 704 bytes in ascii, 38% larger than its implementation!)

How?

See blog post: SectorC: A C Compiler in 512 bytes

Why?

In 2020, cesarblum wrote a Forth that fits in a bootsector: (sectorforth)

In 2021, jart et. al. wrote a Lisp that fits in the bootsector: (sectorlisp)

Naturally, C always needs to come and crash (literally) every low-level systems party regardless of whether it was even invited.

Running

Dependencies:

  • nasm for assembling (I used v2.16.01)
  • qemu-system-i386 for emulating x86-16 (I used v8.0.0)

Build: ./build.sh

Run: ./run.sh your_source.c

NOTE: Tested only on a MacBook M1

What is this useful for?

Probably Nothing.

Or at least that's what I thought when starting out. But, I didn't think I'd get such a feature set. Now, I'd say that it might be useful for someone that wants to explore x86-16 bios functions and machine model w/o having to learn lots of x86 assembly first. But, then again, you should just use a proper C compiler and write a tiny bootloader to execute it.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言