Sunday, May 8, 2011

A CPU State Machine

This is not exactly Ham Radio, but it does help satisfy my need to do some programming.

Late last year I saw a YouTube Video showing the efforts of a MineCraft Gamer building an Arithmetic Login Unit (ALU) using gaming blocks. It was very cool. Later I read Mark's (of description of a simple ALU.

Recently I have been playing with a program called DSPExplorer by Ward - AE6TY (see previous post). The program is normally used to interactively create and explore DSP circuits and functions. The program is a very small Java app and it runs on most systems; MS Windows, Mac, and Linux.

While working with the program, it occurred to me that I should be able to build some simple logic circuits, and then connect them together and watch the logic flow. DSPExplorer is intended to provide easy manipulation of arrays of double precession numbers and has support for imaginary numbers used with FFT and DSP computation. It is a very comprehensive software package.

But, DSPExplorer does NOT support boolean or bit operations, it does NOT have a proper "int" data type.

For my first simple logic experiments, double precession integers work fairly well, for constructing logic blocks that could be interactive connected together to form complex logic operations. I built the usual FlipFlops, AND, OR, and other gates. It was fun watching the DSPExplorer Simulation work it's magic with the defined modules.

Then I remembered the MineCraft Videos, if they can build a simple but complete ALU using "rocks and fire", I should be able to do the same with DSPExplorer programmable interactive math units.

I decided to build an ALU. After many frustration attempts, to do bit operations with double precession number without bit operators, I finally got it to work. I now have a DSPExplorer Logic block made using double precession math (it was much harder than I had thought). If I remember correctly, Ward mentioned that "double" is loosely defined to be as large as the user requires (I think). That means my ALU could potentially be very wide.

ALU (center right) and State Test Modules (upper left) are Shown

The current defined ALU's width is user specified and it implements, the following:
  • X input
  • Y input
  • Flag input (which a 6-bit word that controls the action)
  • O output (the Accumulator)
Most ALU functions are provided, the same as the MineCraft implementation.

Later, decided to expand my initial effort.

Now I have a ROM block to hold Assemble programs, and a State Machine (or CPU) for program flow control. Currently the CPU implements simple: NOP, HALT, JMP, GOTO, PAUSE and ALU OPs, with the output going to the ALU's Flag input word. But, I have not figured out how to return the ALU Accumulator value, but that will be later.

The CPU reads the ROM, and executes the programmed instructions. A partial ROM example is shown on the right, the lower part is a section of Assembly program to be executed by the implemented CPU.

Soon, I should have all of the modules; ROM, RAM, StateMachine, ALU, Buffers,  all needed to implement a more complex system.

With it I may be able to implement a simple compiler, if so, I could write an implementation of java, and therefore, run Ward's DSPExplorer from within this simulation, . . .  Nah, . .  just kidding!

So, why did I do this? Because it was fun, and I am learning a lot about the low level CPU internals.

Note: This is a very Perverse use of the Ward's wonderful DSPExplorer Software, Sorry about that Ward, I will return your program to it's normal use, later.


No comments:

Post a Comment