Files
forth_bootslop/references/ForthNotes/milliForth.md
2026-02-19 16:16:24 -05:00

18 KiB
Raw Permalink Blame History

milliForth

Source: https://github.com/fuzzballcat/milliForth

GitHub - fuzzballcat/milliForth: A FORTH in 340 bytes — the smallest real programming language ever as of yet.

Skip to content

Navigation Menu

Toggle navigation

Sign in

Appearance settings

Search or jump to...

Search code, repositories, users, issues, pull requests...

Search

Clear

Search syntax tips

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel Submit feedback

Saved searches

Use saved searches to filter your results more quickly

Name

Query

To see all available qualifiers, see our documentation.

Cancel Create saved search

Sign in

Sign up

Appearance settings

Resetting focus

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

fuzzballcat / milliForth Public

A FORTH in 340 bytes — the smallest real programming language ever as of yet.

License

MIT license

623 stars 28 forks Branches Tags Activity

Star

Notifications You must be signed in to change notification settings

Additional navigation options

fuzzballcat/milliForth

master

BranchesTags

Go to file

Code

Open more actions menu

Folders and files

Name Name Last commit message Last commit date
Latest commit History42 Commits 42 Commits
.gitignore .gitignore
LICENSE LICENSE
README.md README.md
bf.FORTH bf.FORTH
hello_world.FORTH hello_world.FORTH
makefile makefile
py_autotype.py py_autotype.py
sector.asm sector.asm
sector.bin sector.bin
View all files

Repository files navigation

milliForth

A FORTH in 336 bytes — the smallest real programming language ever, as of yet.

milliFORTH_justhelloworld The code in the above gif, that of [an older version of] hello_world.FORTH, is a modified version of the hello world program used by sectorFORTH (see below)

bytes?

Yes, bytes. This is a FORTH so small it fits in a 512-byte boot sector. This isn't new — sectorFORTH1 successfully fit a FORTH within the boot sector. However, milliFORTH appears to be the smallest "real" programming language implementation ever, beating out sectorLISP2, a mind-blowing 436 byte implementation of LISP, by 96 bytes. ("real" excludes esolangs and other non-production languages - for example, the sectorLISP author's implementation of BF is just 99 bytes, but it clearly isn't used to any serious capacity.) It's now even smaller thanks to some really neat suggestions!

Is it turing-complete?

Yes! This project now includes bf.FORTH, a compliant brainfuck interpreter, to illlustrate that this is truly a real language.

Language

sectorFORTH1 was an extensive guide throughout the process of implementing milliFORTH, and milliFORTH's design actually converged on sectorFORTH unintentionally in a few areas. That said, the language implemented is intentionally very similar, being the 'minimal FORTH'.

FORTH itself will not be explained here (prior understanding assumed). Being so small, milliFORTH contains just a handful of words:

Word Signature Function
@ ( addr -- value ) Get a value at an address
! ( value addr -- ) Store a value at an address
sp@ ( -- sp ) Get pointer to top of the data stack
rp@ ( -- rp ) Get pointer to top of the return stack
0# ( value -- flag ) Check if a value does not equal zero (-1 = TRUE, 0 = FALSE)
+ ( a b -- a+b ) Sum two numbers
nand ( a b -- aNANDb ) NAND two numbers
exit ( r:addr -- ) Pop from the return stack, resume execution at the popped address
key ( -- key ) Read a keystroke
emit ( char -- ) Print out an ASCII character
s@ ( -- s@ ) The "state struct" pointer. The cells of this struct are, in order: * state: The state of the interpreter (0 = compile words, 1 = execute words) * >in: Pointer to the current offset into the terminal input buffer * latest: The pointer to the most recent dictionary space * here: The pointer to the next available space in the dictionary

On a fundamental level, milliFORTH the same FORTH as implemented by sectorFORTH, with a few modifications:

  • All of the interpreter state words are bundled into a single struct (s@).
  • Words don't get hidden while you are defining them. This doesn't really hinder your actual ability to write programs, but rather makes it possible to hang the interpreter if you do something wrong in this respect.
  • There's no tib (terminal input buffer) word, because tib always starts at 0x0000, so you can just use >in and don't need to add anything to it.
  • In the small (production) version, the delete key doesn't work. I think this is fair since sectorLISP doesn't handle backspace either; even if you add it back, milliFORTH is still smaller by a few bytes.
  • Error handling is even sparser. Successful input results in nothing (no familiar ok.). Erroneous input prints an extra blank line between the previous input and the next prompt.

Use

sector.bin is an assembled binary of sector.asm. You can run it using make emulate, which invokes (and thus requires) qemu-system-i386, or by using any emulator of your choice.

Alternatively, make will reassemble sector.asm, then run the above qemu emulator.

Additionally, you can run an example file easily by running make runfile file=SOURCE_CODE. Try out make runfile file=hello_world.FORTH or make runfile file=bf.FORTH! NOTE: Files run this way currently do not accept user input from stdin, as the file itself is being piped to qemu. Fix coming shortly.

make sizecheck is a utility which assembles sector.asm into sector.bin and then lists out the size of sector.bin for you. Note that this automatically removes the padding from the .bin (as a working bootloader must be exactly 512 bytes).

References

Footnotes

  1. The immensely inspirational sectorForth, to which much credit is due: https://github.com/cesarblum/sectorforth/. ↩2
  2. Mind-blowing sectorLISP: https://justine.lol/sectorlisp2/, https://github.com/jart/sectorlisp.

About

A FORTH in 340 bytes — the smallest real programming language ever as of yet.

Resources

Readme

License

MIT license

Uh oh!

There was an error while loading. Please reload this page.

Activity

Stars

623 stars

Watchers

10 watching

Forks

28 forks

Report repository

Releases

No releases published

Packages 0

No packages published

Contributors 2

Languages

© 2026 GitHub, Inc.

You cant perform that action at this time.