One-Der the 32-bit 1 instruction CPU

I’ve talked a bit about One-Der my 32-bit CPU project before. It finally has seen the light of day.

Here’s the article in DDJ:¬†http://www.drdobbs.com/embedded-systems/the-one-instruction-wonder/221800122

 

 

Hands on with One-DEr

Here’s the simulator in action (actually the simulator has had a face lift and has more verbose commands and better output now):

 

Coming soon: A Forth compiler, interrupts, debugging support and more!

Xilinx Education

If you use the Xilinx FPGA tools (or you’d like to) you may have noticed that Xilinx has an “education” link on their home page. Of course, the main purpose of this link is to sell you fairly pricey instructor-led training (actually, it is pretty reasonable for this kind of class, but more than most of us will pony up out of our own pockets).

However, there are several of the shorter classes available online for free. You do have to register, but the price is free. Some pretty good classes on the Xilinx-specific tools. Don’t expect the Verilog, VHDL, or even the “designing with FPGA” classes for free, but there are titles regarding usage of constraints, basic FPGA architecture, and several other interesting topics.

Check out . It isn’t really clear that some of the classes are free until you “drill down a bit,” so be sure to explore.

More on my Homebrew CPU

I’ve mentioned the homebrew CPU on the Spartan 3 board I’ve been building for the last year. The internal architecture is sort of “old school” — internally there is a 16-bit bus connecting all the processor resources. Fixed logic handles all the operations (that is, it isn’t microcoded).

I call it Spartan Blue because it is very loosely based on “Blue” the CPU used as a learning tool in Caxton Foster’s excellent (but dated) Computer Architecture text book. However, Spartan Blue is a lot more advanced than Blue. My version incorporates indexing, a stack, conditional skips, and several other “advanced” features. All instructions complete in one “super cycle” or less (short instructions restart the super cycle; all of the original Blue’s instructions finished in one or two super cycles).

I don’t know if anyone ever built a real “Blue” machine — I know the book has a few errors in it. And my design is different enough that it isn’t really “Blue” at all. But you have to wonder if anyone ever made a faithful reproduction of Foster’s machine.

For the assembler I originally started writing it in awk. However, that proved too limiting so I had it autoconverted into Perl and then continued writing it in Perl. This allows for constant expressions and several other features. I recently “discovered” that Perl has long shipped with perlcc which lets you compile your Perl program to an executable. A shell script calls the C preprocessor before it launches the assembler, so overall it is a pretty powerful system without much work.

Here’s part of the monitor software:

call print_msgcr+CODEOFFSET
ds “Blue Monitor 0.4\xFF”

prompt: call print_msg+CODEOFFSET
ds “\r\r\nBLUE> \xFF”

prompt0:
call waitcharecho+CODEOFFSET


JMPIF(lf+CODEOFFSET,prompt0+CODEOFFSET)

More later.

Update: You can see Blue in action:

Getting Started with Programmable Logic

If you’ve never worked with CPLDs or FPGAs, it can be quite a steep learning curve to get started. Why bother? Programmable logic lets you build real circuits on silicon instead of simulating them with a microprocessor. For example, suppose you want to build a super alarm system with 100 inputs. With a microprocessor, you’d have to examine all the inputs (probably in groups of 8 or 16 or 32) which means while you are examining one set of inputs, the others aren’t being examined. Sure, you could use interrupts, but even then, you’ll only really “see” one input at a time and respond to it.

With programmable logic, you can literally look at 100 inputs in parallel and take action on them rapidly. That’s because a programmable logic chip produces dedicated hardware that you can reconfigure, not a software simulation.

A while back I put together for the local ham radio club about how to get started with programmable logic. It isn’t very in depth (but there are some links to tutorials in it), but it is a good starting point.

By the way, I’m using the excellent

to publish these slides here. Pretty cool, huh?

Processor Open Source

As I’ve mentioned, I like designing CPUs in Verilog for FPGAs. I’ve seen Sun’s major release of some of its SPARC products, but always thought they’d be too large for typical FPGAs.

However, I notice the source is available — might have some promise. Of course, there are plenty of “amateur” cores at and if you aren’t inclined to design your own.

More on the Spartan 3 Starter Kit Computer

I promised a bit more about the computer I’ve built around the Spartan 3 Starter Kit. Let me tell you a bit about the front panel. The CPU is a 16-bit machine with a 12-bit address bus (4K words or 8K bytes of memory). But the board doesn’t have enough I/O to actually support this via the front panel. So a little ingenuity was required.

The board has 4 numeric digital displays. These can display hex (if you provide a hex decoder in the FPGA) so that’s enough to show a single 16-bit quantity. Each digit also has a decimal point which will become important later.

The board also has 8 toggle switches, 8 discrete LEDs, and only 4 push buttons that you can use. Let’s start with the 4 buttons. The leftmost button is predefined to the FPGA’s reset line, so it is the reset button. The next button selects the mode of the front panel (there are 6 modes that you select sequentially — each button press picks the next mode). The second to last button is an “execute” button that means different things depending on the current mode. The final button works as an “enter button” in all modes. Of the 8 LEDs, 6 are dedicated to showing the current mode.

Mode 0 – Register select

In this mode, each press of the enter key changes what register the display shows. The display can show 4 different registers and which one it shows is indicated by which decimal point is turned on. When the rightmost decimal point is on, the display shows the program counter (PC). The next LED signifies the accumulator is displayed. The 3rd LED indicates the “switch” register (more on that in a second). The final LED indicates the instruction register (IR) is displayed.

Note that in all modes, when you press the enter key and hold it down, the front panel does three things:

  1. It shifts the switch register left 8 bits
  2. It puts the current 8 switches into the right 8 bits of the switch register
  3. It displays the switch register (and the corresponding decimal point) until you release the button

So to enter A105 into the switch register, you have to enter A1 into the switches, press enter, and then enter 05 into the switches and press enter again.

Mode 1 – Set PC
Pressing execute in this mode transfers the switch register to the program counter.

Mode 2 – Dump
In this mode, every press of the execute button puts the contents of the memory at the PC into the accumulator and increments the program counter. You can use this to examine memory.

Mode 3 – Load

This is similar to mode 2 except that pressing the execute button puts the contents of the switch register into the memory at PC and increments PC. In addition, in this mode (and assuming the processor is halted) any bytes that show up on the serial port will be entered as though they were entered at the switches. This is a handy way to load an initial program over the serial port (sort of like a paper tape reader).

Mode 4 – Single Step
This mode causes the program to step each time you press execute.

Mode 5 – Run
When in mode 5, pressing execute will start the processor running (or stop it if it is running already).

The two leftmost LEDs are used to indicate status. The very leftmost LED is the Q LED which the program can turn on and off (useful for debugging). The next LED turns on when the processor is running.

This is surprisingly flexible and is pretty quick to operate once you get the hang of it. Of course, you don’t want to enter long programs which is why there is the serial port option.

The switch register can be read and written under program control. The program can also read the raw value of the switch inputs. These are mapped, along with the UART registers, to the top part of the memory (FF0-FFF are reserved for I/O).

So that gives you a little flavor of what I do in my spare time. Next time I’ll talk about the instruction set (which includes a stack, indexing, and a few other interesting instructions).

Xilinx Spartan 3 Starter Kit

I bought a Xilinx Spartan 3 Starter kit awhile back for about $100. Great bargain! This board has an FPGA that can hold 10s of thousands of logic gates. Why use FPGAs instead of microcontrollers? FPGAs are real hardware. Say you design 10 PWM outputs in hardware. Then all 10 run at the same time. In a microcontroller, you have to do a few instructions for one PWM and then a few for the other… and so on (or at least, some variation thereof). So even a fast processor quickly gets divided down. Another way to look at it is that if you have a processor running at 10MHz in a loop with 10 instructions, you are effectively operating at 1MHz! With an FPGA everything happens in hardware all at the same time.

I have a custom CPU I designed working pretty well on the board. I’ll occasionaly share a little about some projects I’ve done with the board here on HotSolder.