(back home)

kmx20 stack cpu

This serves as documentation for the kmx20 architecture, which is incomplete.

It is a work-in-progress effort and will be updated regularly, currently without much regard for backwards compatibility.


Numbers on the stacks are 32 bits. These are referred to as words.

16 bits is a half and 8 bits is a byte; some instructions work with integers at these sizes.

Hardware Registers

The kmx20 cpu iself has 3 hardware registers.


The kmx20 has 2 data busses, one for memory access, and one for i/o access.

Instruction Encoding

Instructions each take a byte in memory.

  ||O: Opcode
  |F: Flip return and data stacks
  K: Keep all left hand operands


Val Op Stack effect Description
0x00 np -- no-op
0x01 ex -- halt execution
0x02 pb --n puts the next byte (8 bits) in memory onto the stack
0x03 ph --n ^ same but next half-word (16 bits)
0x04 pw --n ^ same but next word (32 bits)
0x05 pr --n puts ip+the next byte plus onto the stack
0x06 fb a--n fetches a byte from address a and puts it onto the stack
0x07 fh a--n ^ same but with half-word
0x08 fw a--n ^ same but with word
0x09 mb n a-- truncate stack item n into a byte and put it in memory address a
0x0a mh n a-- ^ same but with half-word
0x0b mw n a-- ^ same but with word
0x0c io n p-- move cell n to io port p
0x0d ii p--n gets cell from io port p and pushes it onto the stack
0x0e ss n-~n move cell from data stack to return stack
0x0f dr n-- drop item from data stack
0x10 sw n m--m n swap items
0x11 du n--n n duplicate item on data stack
0x12 ov n m--n m n bring second item on data stack over
0x13 ad n m--n+m add
0x14 a1 n--n+1 add 1
0x15 su n m--n-m subtract
0x16 s1 n--n-1 subtract 1
0x17 mu n m--n*m multiply
0x18 di n m--n/m n%m div rem
0x19 an n m--n&m bitwise and
0x1a or n m--n or m bitwise or
0x1b xr n m--n xor m bitwise xor
0x1c sl n m--n shl m bitwise shift left
0x1d sr n m--n shr m bitwise shift right
0x1e sa n m--n ashr m bitwise arithmetic shift right
0x1f eq n m--n==m logical equals
0x20 lt n m--n<m logical less than
0x21 gt n m--n>m logical greater than
0x22 no n--!n logical not
0x23 ju a-- jump to address a
0x24 jc n a-- jump to address a if n!=0
0x25 ca a-~r push ip onto return stack, then jump to address a
0x26 cc n a-~r push ip onto return stack and jump to address a if n!=0