A Simple CPU

This CPU has 14 commands. There are 4 argument types:

Argument Type Example Description Bit Code
Immediate jump #0x1234 Jumps to the address 0x1234 00
Memory jump 0x1234 Jumps to the adress, which is stored at 0x1234 01
Memory Indirect jump (0x1234) Jumps to the address, which is stored at the address, which is stored at 0x1234 10
Special jump [0x1000] Jumps to the address, which is stored in the special position 0x1000, e.g. external DIP switches 11

The program counter (pc) is 16 bit width. There are 2 state registers: Carry (c) and Zero (z). The command list:

Command Description Flags Opcode
move from, to to = from   000faabb
add arg, to to = to + arg c = x, z = x 001faabb
sub arg, to to = to - arg c = x, z = x 010faabb
mul from, to to = from * to c = x, z = x 011faabb
bcc to branch, if c=0   100faa00
bcs to branch, if c=1   100faa01
beq to branch, if z=1   100faa10
bne to branch, if z=0   100faa11
and arg, to to = arg and to z = x 101faabb
xor arg, to to = arg xor to z = x 110faabb
jump to pc = to   111faa00
lsl to to = shift left to c = x, z = x 111faa01
lsr to to = shift right to c = x, z = x 111faa10
nop no operation   11111111

"x" for the flags means, that this register is changed according to the result: z=1, if the result is zero, otherwise z=0. c=1, if the result for "add" and "mul" is greater than 0xffff or if the result for "sub" is less than 0. "aa" and "bb" is the argument bit code for the first and second argument.

All argument types are 16 bit wide by default. When storing and reading data, the byte order is the network byte order, big endian (the most significant byte is stored first).

If the "f" flag is set (which is marked like "move.b #10, 0x1234"), then immediate arguments are 8 bit wide and transfers from and to memory and special locations are 8 bit wide. Memory addresses are always 16 bit wide. In 8 bit mode, jump and the branches are relative to the pc of the next instruction and the argument is used as a two's complement signed 8 bit offset.


20. August 2006, Frank Buß