Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Digital Logic Sim

​A minimalistic digital logic simulator · By Sebastian Lague

8-BIT RISC CPU

A topic by Murat_two created 9 days ago Views: 110 Replies: 1
Viewing posts 1 to 2

I made a RISC CPU that have 16 registers. The first 6 are write only registers (First 4 are for screen and other 2 for buzzer) and the register 6 and 7 are outputs, they can use like normal registers or second buzzer (I use them for extra memory, maximum usage can be 64KB ROM and RAM or 16MB ROM and 1/4 KB RAM) . Also the 8th register is for keyboard input, all of possible keys (0-9 and A-Z) have som codes. The CPU also have addition, subtraction, multiplication and division. The multiplication and division is at 1-tick speed (very fast). You can do anything you want with this CPU.


This is the instruction set of it:

  • 0000: NOP
  • 0001: LOAD Rx ADDR
  • 0010: STORE Rx ADDR
  • 0011: MOV Rx Imm
  • 0100: ADD Rx Ry Rz
  • 0101: SUB Rx Ry Rz
  • 0110: MUL Rx Ry Rz
  • 0111: DIV Rx Ry Rz
  • 1000: MOD Rx Ry Rz
  • 1001: JMP POS
  • 1010: JE POS (First use CMP then use this and CPU only have 1 logic register (1/0) and it can't be directly store in RAM but if you use some CMP, MOV and STORE commands maybe you can)
  • 1011: CMP OP Rx Ry (OP means operation code at bottom of instruction set you can find operation codes)
  • 1100: AND Rx Ry Rz
  • 1101: OR Rx Ry Rz
  • 1110: XOR Rx Ry Rz
  • 1111: RND Rx

In this instruction set some commands (AND, OR, MUL, MOD, CMP, DIV, ...) have 3 register inputs: Rx, Ry and Rz. The Rx is output, Ry is first term and Rz is the second term. For example: SUB Rx Ry Rz = Rx = Ry - Rz.

Operation code instruction set:

  • CMP 0000: FALSE
  • CMP 0001: TRUE
  • CMP 0010: EQ
  • CMP 0011: NEQ
  • CMP 0100: GT (Greater Than)
  • CMP 0101: GE (GT or EQ)
  • CMP 0110: LT (Less Than)
  • CMP 0111: LE (LT or EQ)

The other commands (1xxx) are don't do anythings. Also the CPU is unsigned so you can't do anything with negatives but if you wan't so you can use first bit for symbol (+/-) and for CMP you can say if X>01111111 it's negative and other things.

Registers and special commands:

  • R0: Screen Position
  • R1: Screen Red
  • R2: Screen Green
  • R3: Screen Blue
  • R4: Buzzer Pitch
  • R5: Buzzer Volume (In first it can be random so please make it 0 in first)
  • R6&7: Extra Outputs
  • R8: Keyboard Input
  • JMP 0: Reset Screen
  • JMP 1: Write Screen
  • JMP 2: Refresh Screen
  • JMP 3: Empty Position (You can't jump in to here)
  • Position 4: Start Position (For some usage it can be 5 or 6 maybe) 

" SPOTTED BUG! "

This is a random point writer program. And you can see the probability distribation of CPU and it's very strange.

I think this is a bug because of i use a digital logic sim feature that if you connect a zero and one in to a bus it will be random but in this situtation you can see that when there is a rising edge in clock some of this randomness modules gives only 0 or 1.