DWMC-16: Initial Instruction Set – Deprecated

With some of the basics out of the way, I think I can now deal with an initial instruction set for the computer. I plan to do a somewhat minimal instruction set, but I do not think I will be able to keep it at less than 32 instructions as ‘Minimal Instruction Set Computing’ requires.

Legend

RdDestination Register
Rs, Rs2Source Registers
PRProgram Counter
CConstant Number
AddrMemory Address
STStack Pointer
FFlag bit
MSBMost Significant Bit
LSBLeast Significent Bit

Data Transfer Operations

Load Direct/Indirect

Load Directld Rd, AddrRd <= Memory[Addr]
Load Indirectldi RdRd <= Memory[Z]

Effected Flags: None

These operations load a value from memory, either directly by giving the address or indirectly from the Z Address Register. The latter necessitates an Adress to be saved in the Z register.

Store Direct/Indirect

Store Directst Rs, AddrMemory[Addr] <= Rs
Store Indirectsti RsMemory[Z] <= Rs

Effected Flags: None

These operations store a value to memory, either directly by giving the address or indirectly from the Z Address Register. The latter necessitates an Adress to be saved in the Z register.

Move

Movemv Rd, RsRd <= Rs

Effected Flags: None

This operation copies the value of Register Rs into Register Rd.

Arythmic Logical Operations

Arythmic Operations

Addadd Rd, RsRd <= Rd + Rs
Incrementinc RdRd <= Rd + 1
Substractsub Rd, RsRd <= Rd – Rs
Decrementdec RdRd <= Rd – 1

Effected Flags: C, QC, HC, TC, Z, N, O

These operations add/subtract the Source register to/from the Destination Register.

Logical Operations

Bitwise ANDand Rd, RsRd <= Rd & Rs
Bitwise ORor Rd, RsRd <= Rd | Rs
Bitwise XORxor Rd, RsRd <= Rd ^ Rs
Bitwise NOTnot RdRd <= ~Rd

Effected Flags: Z

Shift Operations

Logical Shift Leftlsl RdRd <= Rd << 1
LSB <= Carry
Carry <= MSB
Logical Shift Rightlsr RdRd <= Rd >> 1
MSB <= Carry
Carry <= LSB
Logical Rotate Leftlrl RdRd <= Rd << 1
LSB <= MSB
Logical Rotate Rightlrr RdRd <= Rd >> 1
MSB <= LSB

Effected Flags: C, Z

These operations logically shift/rotate the binary value of the Destination Register by one bit left/right.

Conditional Branch Instructions

Simple Branch Operations

Branch if Flagbz F, Addrif (F == 0): PC <= Addr
Branch if not Flagbnz F, Addrif (F != 0): PC <= Addr

Effected Flags: None

These operations are simple branch instructions to test whether a previous operation set/reset a flag. The flag itself should be designated by its bit.

Complex Branch Operations, Single Register

Branch if Zero, Decrementbzd Rd, Addrif (Rd == 0): PC <= Addr
else Rd <= Rd – 1
Branch if not Zero, Decrementbnzd Rd, Addrif (Rd != 0): PC <= Addr
else Rd <= Rd – 1
Branch if Register Zerobrz Rs, Addrif (Rs == 0): PC <= Addr
Branch if Register not Zerobrnz Rs, Addrif (Rs != 0): PC <= Addr

Effected Flags: C, Z, N

These operations are more complex branch operations, testing a single register. The Branch, Decrement operation is specially meant for counting loops, which are rather important in computing.

EDIT: brz/brnz Rs, Addr can be replaced by breq/brnw Rs, Zero, Addr.

Complex Branch Operations, Two Registers

Branch if Registers Equalbreq Rs, Rs2, Addr if (Rs == Rs2): PC <= Addr
Branch if Registers not Equalbrne Rs, Rs2, Addrif (Rs != Rs2): PC <= Addr
Branch if greater thenbgt Rs, Rs2, Addrif (Rs > Rs2): PC <= Addr
Branch if smaller thenblt Rs, Rs2, Addrif (Rs < Rs2): PC <= Addr
Branch if greater then or equalbge Rs, Rs2, Addrif (Rs >= Rs2): PC <= Addr
Branch if smaller then or equalble Rs, Rs2, Addrif (Rs <= Rs2): PC <= Addr

Effected Flags: C, Z, N

These operations are more complex branch operations, comparing the value of two registers.

EDIT: blt/ble Rs, Rs2, Addr can be replaced by bgt/bge Rs2, Rs, Addr.

Other Operations

Unconditional Jump Operations

Jump Directjmp AddrPC <= Addr
Jump IndirectjmpiPC <= Z
Jump to Subroutinejms AddrST <= PC + 1;
PC <= Addr
ReturnretPC <= ST

Effected Flags: None

These operations are for jumping through the program. For the jump to a subroutine and the return, the Stack Pointer is automatically incremented/decremented.

Stack Operations

Push to Stackpush RsST <= Rs
Pop from Stackpop RdRd <= ST

Effected Flags: None

These operations are meant for storing/loading values to/from the stack.

Flag Operations

Set Flagsf FF <= 1
Reset Flagrf FF <= 0

Effected Flags: Any

These operations are meant for setting/resetting any flag.

Other Operations

No operationnopNo operation

Effected Flags: None

Conclusions

With currently 38 34 operations in the Instruction Set, with a clear majority being branch operations.

This may or may not be the final iteration of the Instruction set, but it is certainly a beginning, and I’m going to use it to begin to work on the control logic of the CPU. Most likely, I will use a full microcode system, which would make adding more operations later on relatively simple.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.