mirror of https://git.cro.wtf/kip.git
3.5 KiB
3.5 KiB
title: kip manual: kmx20
...
# kmx20 cpu
This document is heavily incomplete. It is a work-in-progress effort.
## Hardware registers
The kmx20 has 3 hardware registers,
-
ip
Word
Instruction pointer
- dp
Byte
Data Stack Pointer
- rp
Byte
Return Stack Pointer
## Busses
The kmx20 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.md for kip computer i/o
## Instructions
Instructions take 1 byte in memory. Each binary digit corresponds to
XFOOOOOO |||O: Opcode ||F: Flip return and data stacks || (eg 01000010 will put the next byte in memory onto the return stack) |K: Keep left hand operands | (eg (a--n) below becomes (a--a n)) |X: Unused
## Opcodes
| Op | Stack effect | Description |
|----|--------------|-----------------------------------------------------------------------------|
|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) |
|pr
|--n
| puts ip+the next byte plus onto the stack |
|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 |