Weft-8 · hardware

one machine · two implementations · one answer

The same 8-bit computer,
not just in a browser.

The Loom's Weft-8 is about 180 lines of C here as well as a single JavaScript file — sixteen registers, four flags, 256 bytes, twenty-seven instructions. Eleven programs, with results worked out by hand, must agree across all three: the hand computation, the C machine, and the JavaScript one. If any of them drifts, the build goes red.

/* the whole machine, in one switch */
case W8_ADD:
    va = m->r[a]; vb = m->r[b];
    res = (unsigned)va + vb;
    m->r[a] = (uint8_t)res;
    m->c = res > 0xFF;
    m->v = (((va ^ res) &
             (vb ^ res)) & 0x80) != 0;
    set_nz(m, m->r[a]);
    break;
16 registersZ C N V256 bytes27 opcodes2 bytes each

Why a C port is the honest test

A machine described in one language can hide a mistake inside that language's habits. A second implementation, written from the same specification and checked against an independent answer, cannot.

1 · the answer

Ten programs with results computed by hand from the ISA — registers, flags and what reached the ports.

2 · the C machine

c/weft8.c and c/weft8.h. Built with gcc -O2, run over the corpus in CI.

3 · the JavaScript machine

The Loom's own weft8.js, byte for byte — the engine every other Weft app runs.

The corpus — eleven programs

Every row is a claim about the machine, and each one is checked three ways.

programwhat it proves
add5 + 7 lands in a register, no flags raised
borrow2 − 5 wraps to 0xFD and sets carry and negative
overflow127 + 1 sets overflow, which is what makes signed branches correct
countdowna loop runs exactly five times
signed−1 is less than 1, though 255 is greater
stackPUSH/POP return values in reverse order
callretCALL and RET come back to the right place
ramSTORE then LOAD round-trips through scratch RAM
shiftSHL moves the top bit into carry
portstwo bytes written to a port arrive in order
signed-cmp−2 is less than −1, so a signed branch works on negatives

the weft-8 family — one machine, seven faces

the Loomthe machine and its editor — where it all starts Weft Puzzlesfive puzzles solved in assembly, a robot on a grid Clip Loomclipboard programs you can read: strip, squeeze, wrap
Weft-8 on hardwareyou are here
weft8-kitrules small enough to sign off Weft-8 Classroomeight exercises that teach how a computer works Weft-8 beside x86 and ARMthe same four jobs in three machines

Every one of these runs the same engine — weft8.js from the Loom, byte for byte. Learn it once and you have learned all seven.