mirror of https://git.cro.wtf/kip.git
89 lines
2.9 KiB
Plaintext
89 lines
2.9 KiB
Plaintext
KMM32 CPU
|
|
|
|
This document is heavily incomplete and may be at parts incorrect. It is a
|
|
work-in-progress effort.
|
|
|
|
HARDWARE REGISTERS
|
|
|
|
The KMM32 has 3 hardware registers,
|
|
ip -- (Word) Instruction pointer
|
|
dp -- (Byte) Data Stack Pointer
|
|
rp -- (Byte) Return Stack Pointer
|
|
|
|
BUSSES
|
|
|
|
The KMM32 has 2 data busses.
|
|
mem -- Memory Bus
|
|
Byte-addressed
|
|
Where data is to be read and writ
|
|
|
|
+---0x00000---+ <-- Interrupt Vector Table
|
|
| (rwx) |
|
|
+---0x00100---+ <-- Boot
|
|
| (rwx) | This is where the CPU resets to,
|
|
| | and where the emulator puts
|
|
| | loaded ROMs.
|
|
. .
|
|
. .
|
|
|
|
| |
|
|
+---0x40000---+ <-- Data Stack
|
|
| (rw-) | Word-addressed by `dp
|
|
+---0x40400---+ <-- Return Stack
|
|
| (rw-) | Word-addressed by `rp
|
|
+---0x40800---+
|
|
|
|
io -- Input/Output Bus
|
|
Word-addressed
|
|
Peripherals are directly connected to this bus
|
|
|
|
(see ./kip for kip computer i/o)
|
|
|
|
INSTRUCTIONS
|
|
|
|
Opcodes take 1 byte in memory.
|
|
Each binary digit corresponds to:
|
|
UFOOOOOO
|
|
O: Opcode
|
|
F: Flip return and data stacks
|
|
U: Unused
|
|
|
|
OPCODES
|
|
|
|
np (--) no-op
|
|
ex (--) halt execution
|
|
pb (--n) puts the next byte (8 bits) in memory onto the stack
|
|
ph (--n) ^ same but next half-word (16 bits)
|
|
pw (--n) ^ same but next word (32 bits)
|
|
fb (a--n) fetches a byte from address `a and puts it onto the stack
|
|
fh (a--n) ^ same but with half-word
|
|
fw (a--n) ^ same but with word
|
|
mb (n a--) truncate stack item `n into a byte and put it in memory address `a
|
|
mh (n a--) ^ same but with half-word
|
|
mw (n a--) ^ same but with word
|
|
io (n p--) move cell `n to io port `p
|
|
ii (p--n) gets cell from io port `p and pushes it onto the stack
|
|
ss (n-~n) move cell from data stack to return stack
|
|
dr (n--) drop item from data stack
|
|
sw (n m--m n) swap items
|
|
du (n--n n) duplicate item on data stack
|
|
ov (n m--n m n) bring second item on data stack over
|
|
ad (n m--n+m) add
|
|
su (n m--n-m) subtract
|
|
mu (n m--n*m) multiply
|
|
di (n m--n/m n%m)div rem
|
|
an (n m--n&m) bitwise and
|
|
or (n m--n|m) bitwise or
|
|
xr (n m--n^m) bitwise xor
|
|
sl (n m--n<<m) bitwise shift left
|
|
sr (n m--n>>m) bitwise shift right
|
|
sa (n m--n>>>m) bitwise arithmetic shift right
|
|
eq (n m--n==m) logical equals
|
|
lt (n m--n<m) logical less than
|
|
gt (n m--n>m) logical greater than
|
|
no (n--!n) logical not
|
|
ju (a--) jump to address `a
|
|
jc (n a--) jump to address `a if `n!=0
|
|
ca (a-~r) push ip onto return stack, then jump to address `a
|
|
cc (n a-~r) push ip onto return stack and jump to address `a if `n!=0
|