- GNU binutils built for the
mmixtarget (mmix-as,mmix-ld,mmix-ar,mmix-ranlib, and optionallymmix-objdump) - The C preprocessor
cpp - The
mmixsimulator from Knuth's MMIXware bashfor the scripts inbin/
cd lib && make
This compiles the library into lib/libmm.a and creates a number of
special object files (entry.o, mmi.o, guard.o and mmo.o) that are
used by the compiler/linker script for linking a final executable.
bin/mmixc is a small gcc-style driver around cpp, mmix-as and
mmix-ld. It assumes to find include/ and lib/ relative to its own
location.
export PATH="<path to this repository>/bin:$PATH"
mmixc hello_world.mms -o hello_world.mmo
mmix hello_world.mmo
Programs include the headers as #include <mm/print> and define a Main
label. Run mmixc -h for the full list of options. The commonly used ones
are -c (stop after assembling), -E (stop after preprocessing), -v
(print each command), -keep-tmp (keep the intermediate files), and
-Wa,<opt> / -Wl,<opt> to pass options to the assembler or linker.
mmixc links in this order:
entry.o mmi.o <your objects> guard.o -lmm mmo.o
entry.oputs the trip and exception vectors at#00and the program entry point at#F0.mmi.oandmmo.oopen and close the.initsection. Initialization code that library units assemble into.init(the memory pool and the thread ring) ends up between them and runs beforeMain.guard.ofollows the user code. A program that runs past its last instruction instead of calling:MM:Sys:Exithits the guard and aborts with an error message, rather than falling into library code.
To build all examples, run make in examples/ (requires mmixc in
PATH).
bin/binfmt-mmix wraps the mmix simulator. It configures the terminal
before the program starts and restores it afterwards. It recognizes three
options, each written as -mmix <option> on its command line:
-tty-raw-modeputs the terminal in raw mode without echo.-tty-noblockimplies-tty-raw-modeand makes reads non-blocking.-spawn-workerstarts a helper process that runs shell commands for:MM:__SYS:Command(seeexamples/spawn_worker.mmsfor an example).
Any other -mmix <option> is passed through to the simulator. A program
can also request these modes itself by declaring one of the global symbols
MM:Interpreter:TTY_RAW_MODE, MM:Interpreter:TTY_NOBLOCK or
MM:Interpreter:SPAWN_WORKER (see examples/raw_mode.mms). The wrapper
looks for these symbols with mmix-objdump, so this only works if
mmix-objdump is available in PATH.
On Linux, binfmt-mmix can be registered with binfmt_misc so that
.mmo files run directly:
echo ":mmix:E::mmo::<path to binfmt-mmix>:" > /proc/sys/fs/binfmt_misc/register
or permanently by putting the same line into /etc/binfmt.d/mmix.conf.
Preemptive threading (:MM:Thread:Enable, used by
examples/threading.mms) sets the interval counter :rI and expects a
trip when it runs out. The stock mmix simulator treats PUT :rI as a
privileged instruction and stops with "privileged instruction!".
patches/mmix-sim-interval-timer-trip.patch changes the simulator so
that:
PUTto special registers 12 to 18 (rI,rT,rTT,rK,rQ,rU,rV) is allowed in user programs.- When
rIdrops to 4 or below, the simulator trips to#00and resetsrIto -1. The stock simulator stops at an interactive breakpoint instead. rIstarts at -1, so programs that never set it behave as before.
To build the patched simulator from the MMIXware sources at
https://gitlab.lrz.de/mmix/mmixware/ (this needs ctangle from CWEB):
git clone https://gitlab.lrz.de/mmix/mmixware.git
cd mmixware
git apply <path to this repository>/patches/mmix-sim-interval-timer-trip.patch
make mmix
The patch was last checked against commit 90d53fb of the master
branch.
With GCC 15 or newer, the MMIXware sources fail to compile because C23
made bool and false keywords. Build with
make mmix CFLAGS="-O2 -std=gnu17 -Wno-error=implicit-int -Wno-error=implicit-function-declaration"
instead.
Cooperative threading with :MM:Thread:Yield works on the stock
simulator. To build examples/threading.mms in that mode, remove its
#define PREEMPTIVE line.
The heap will be organized as memory blocks inside the pool segment of the
executable. This needs some cooperation from the user: The convention (as
defined by the mmixware documentation) is that M_8[:Pool_Segment] points
to the first unallocated region within the pool address space. User
programs utilizing address space from the pool segment must obey this rule
by 'allocating' memory by modifying M_8[:Pool_Segment] appropriately. The
library assumes that this pointer is OCTA aligned.
-
Neither mmixal, nor GNU guarantee that the contents of the temporary register
$255is preserved after aJMP,PUSHJinstruction, orLDApseudo instruction. The assembler is free to use$255to construct an absolute address if the target label cannot be reached by a near jump. Thus, when calling a library subroutine the contents of$255might not be preserved. -
Similarly, the library might use
:MM:tinternally. Thus, when calling a library subroutine - even a nonG-variant - the contents of:MM:tmight not be preserved. (Subroutines generally try to preserve the contents of:MM:t, though).
The library avoids unnecessary allocation of global registers by not using
LDA instructions at the expense of a slight runtime overhead. The library
allocates 3 global registers (GREGs) for internal use and an additional
global register :MM:t for calling library routines (see next section).
Suroutines come in a number of different variants.
- Subroutines without a trailing
J, will terminate the program with an error message (or call an error handler if specified). Variants with a trailingJ, will jump to:rJ+#4on succes and to:rJ+#0on failure (some variants that would return a boolean value jump to:rJ+#4fortrueand to:rJ+#0forfalseinstead.) This can be used to implement customized error handling. An example:
% Try to allocate a block of memory:
SET $1,[...]
PUSHJ $0,:MM:Pool:AllocJ
JMP 1F
... % Allocation was successful, continue normally.
1H ... % Allocation failed, error handling.
- Subroutines that have at most one argument and at most one return
parameter come also in a variant with a trailing
Gwhich indicates that values are passed through the library specific temporary global register:MM:t. An example:
% Try to allocate a block of memory:
t IS :MM:t
SET t,[...]
PUSHJ t,:MM:Pool:AllocG
% Address of allocated memory in t
Copyright (C) 2013-2026 Matthias Maier <tamiko@43-1.org>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.