blob: f8c8b5dc4fc6173ebed9d6b67768efaf22c5a9f5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
|
# the golfed vm
no code from this stage survives except where a code/ folder sits next to this file. these are the notes as they were written in the transcript.
## message 1
> codegolf a tiny cpu vm in C89. the goal is to achieve the lowest character count possible. include an assembler as well (scored separately) and a hello world program (not scored, but elegance and simplicity is a bonus)
> it must be capable of re-entrant code and a realistically workable instruction set.
**summary:** a two-stack forth-style machine. the vm was 384 bytes: one ternary chain inside `while(o=m[p++])`, the top two stack items cached in `a` and `b`, the program loaded with `read(open(...))` so it needs no headers, and both stacks inside the 65536-word memory. it had 22 opcodes including div and mod, a two-word literal, and jump/call targets popped from the stack. the assembler was 348 bytes and two-pass, using `strcspn` instead of `strchr` so the implicit int return stays safe on 64-bit. hello world was a pointer loop over a string with a zero terminator. re-entrancy was shown with a recursive factorial plus a recursive decimal printer.
|