Building an ALU from an EPROM

This blog post is a “what-if” scenario, rather than a practical application.  Still, if EPROMs ever become super fast, this is a viable option.

I’ve discussed Arithmetic Logic Units in previous posts.  I have the circuit for the TTL 74381 and 74382 chips.  The circuit is easy to find on the internet and it’s included in the TTL logic book.  Unfortunately, the chips can not be purchased and are probably discontinued.  So I analyzed the circuit and was attempting to design a GAL equivalent.  Unfortunately, the GAL22V10 doesn’t have enough circuits to emulate the 74381.  I’ll need something more sophisticated.  I’m looking at CPLD devices and FPLAs.  These are probably overkill for an ALU, but I could code something that is 32 bits wide all on one chip.

So I scratched my head and thought, what if I used an EPROM?  First, I counted the inputs and outputs for the circuit.  Here’s the circuit:

The total number of inputs is 12 and, fortunately, the number of outputs is 8.  So this will fit really nice on an AMD 2732.  The 2732 is 4k x 8.  Doing the math on the inputs shows that 2^12 = 4096 or 4k.  So we’ll get an EPROM that has 12 address lines and 8 data lines.

Now for the bummer about EPROM memory… It’s slow.  Typically to the tune of 250ns.  Which is painful compared to the specs for the TTL 74381 running with a max delay time of 33ns.  Jameco has a One Time Programmable PROM that runs at 45ns.  That’s pretty close for an experimental circuit.  Making this a feasible stand-in for the TTL 74381 and 74382.

So now for the dirty part: Convert all inputs into outputs.  I was going to use my logic simulator to simulate all possible inputs, but it runs too slow.  The emulator was designed to study delays not pump out all combinations of inputs.  I had to create a new program to simulate my logic.  This turned out to be easy.

If you click on the diagram above, you’ll see that each gate is uniquely numbered.  That’s how I translated this circuit into my simulator.  For the quick logic, I used boolean for inputs and outputs, then I created a run circuit method that ran the circuit for the given inputs and set the outputs accordingly.  Translating a diagram like this is easy because I purposely arranged my numbering to start from the inputs and work through the circuit sequentially until I reached an output.  So I started inputting logical statements like this:

bool gate0 = !S0;

This is for gate 0’s output.  Basically, gate0 will invert the input S0 (which is a boolean variable I created as a getter/setter).  Continuing on:

bool gate1 = !gate0;
bool gate2 = !S1;
bool gate3 = !gate2;
bool gate4 = !S2;
bool gate5 = !gate4;
bool gate6 = gate4 && gate2 && gate1;

And so on, until I ended up with all the outputs like F0 equal to the exclusive nor of gate63 and gate 71.

I then copied my unit tests from my simulator and translated all 0 and 5volts into false and true.  It took a little debugging but I quickly had the unit tests working and was satisfied with my results.  Next, I wrote a console application to feed all the possible inputs.  At first, I thought I could just keep it stupid easy and just do nested loops, but that was a pain, so I decided to do one for loop consisting of the range of 0 to 4095 and then treat each bit of the integer as one of the inputs.  That was pretty easy.

My next task was to figure out what format my EPROM programmer saved its files in.  This turned out to be Intel Hex.  Never heard of it.  It was only lucky that the save box indicated that it was Intel Hex, otherwise, I would have had a tough time figuring out what all the addressing hex represented:

There is a wiki for Intel Hex.  It’s very descriptive and was handy in figuring out how to compute the checksum and addressing information.  So I coded that and spit out the data for my EPROM programmer.  Unfortunately, the EPROMs that I have are old and seem to be defective (they don’t take the program), so I ordered a new EEPROM from Jameco Electronics.  With the EEPROM I can erase the chip from my programmer instead of using my UV light.

Converting a circuit into an EPROM is feasible if there are no latching mechanisms, timing circuits, or feedback paths.  In this case, the 74381 is just straight logic, so it can be represented with memory very easy.  The 7-segment hex display decoder I did with the GAL16v8 could also be represented as an EPROM.  That circuit needed 8 outputs as well and it uses 6 inputs.  So a tiny 64 x 8 memory would work.

Where to Download the Code

You can download my code and generate your own Intel Hex file by going to my GitHub account here.  Click here to download the hex file I generated.

1 thought on “Building an ALU from an EPROM

Leave a Reply