Electronic – Very simple CPU design in LogiSim


I'm currently a junior in highschool, and I've been interested in computer/electrical engineering, specifically microprocessor design. I've read Code by Charles Petzold, , and have begun reading the Microprocessor Design Wikibook (which seems to be incomplete.) Through reading Code, I understand the basic logic behind a CPU, and have begun building one in LogiSim. Chapter 17 in Code details the CPU I want to build, but the circuits lack key components — clock signals, and instruction decoding. Some of the clock signals seem to be pretty obvious (the PC seems to need a steady clock signal) but others (like how to latch RAM values) I have had to think through and try to get working.

I can build a working accumulator (it can't be accurately called an ALU, I think, because it lacks the L part) that switches between addition and subtraction with a single input, and I understand this is all I need for the arithmetic part — once I get jump opcodes working, I can implement multiplication and division in code. The part I'm struggling with is the instruction decoding. Through some google searches, I see that each opcode needs to be interpreted as multiple microinstructions, but I'm lost as to how I need this to work. Currently, my instruction decoder is just a combinational analysis circuit with a single binary output for each opcode — 13 in all.

The way the code works is it has one 8 bit code value (I only use the low-end byte), and then two separate 8 bit address values that I then combine to be the 16 bit address input to the RAM. In order to latch the values, I have a separate counter that counts up to 10b and then resets to 00b. It is the clock input for each latch in turn (for the three latches, there's a, b, and c. the second clocks have a be 1 while b & c are 0, then b is 1 and 1 & c are 0, then c is one and 1 & b are 0, then it resets). But on instructions such as ADD 000Ah, the PC jumps to 000AH…which is supposed to be added into the accumulator, but actually gets latched into the code latch, and is then interpreted as the next opcode, which makes the whole thing go crazy.

I feel like I'm missing some big information regarding instruction decoding and how I need to do clock signals…

Here are the LogiSim .circ files:

PetzoldMk5 is the main CPU, relying on the other files to be imported as libraries.

Here's a list of opcodes (all binary):

Load                 0001
Add                  0010
Add w/ Carry         0011
Sub                  0100
Sub w/ Borrow        0101
Jump                 0110
Jump w/ Carry        0111
Jump W/ 0            1000
Jump w/o C           1001
Jump W/o 0           1010
Store                1011
Halt                 1100
Reset                1101

Best Answer

Hate to post a "link only" like answer, but I think you should be made aware of Warren Toomey's work with CPU's in Logisim, since it's probably exactly what you are looking for.

He has a couple tutorials building up to a reasonably simple CPU here...


And if that doesn't float your boat, he has a more sophisticated CPU here...


... All of which is well explained, and has downloads to .circ files.

Another great, and arguably more functional, DIY CPU/computer is Magic-1 found at http://www.homebrewcpu.com/. Though it's not done in Logisim, it is quite well documented, including pictures, schematic, description. It is also more than just a CPU in a simulator. It has a ANSI C compiler, an OS, and some software. It's also has the distinct advantage of actually having been built in hardware. In fact, it's currently up and running and serving web pages!

Finally The Elements of Computing Systems and the associated site nand2tetris.org comes in as the #1 recommended information resource for building your own computer from the ground up every time I look into it. Much (All?) content is free of charge I believe. YouTube would agree; many people have made projects starting from this one source.

Related Topic