APC Australia

Design your own microproce­ssor

Mike Bedford has a brilliant two-part project for learning how computers work.

-

Most likely, the processor in your PC has upwards of a billion transistor­s. Trying to get your head around the workings of such a complicate­d electronic circuit might, therefore, seems a daunting task. Yet helping you to understand what goes on inside a CPU is the task we’ve set ourselves here. The latest chips are complicate­d by many bells and whistles doing way more than straight “processing”, so we should think of a very basic chip and take it on trust that the principles here can indeed be scaled up.

In 1971, the very first microproce­ssor – the 4-bit Intel 4004 – still had 2,250 transistor­s on board. While that might be a whole lot more manageable than a couple of billion, it might still seem to be no mean feat to understand how that worked from an electronic­s viewpoint.

But that this isn’t nearly as difficult to understand as you might fear. The fact is that logic circuitry is created in a so-called bottom-up approach. Transistor­s – the fundamenta­l electronic building block – are used to create logic gates, which are the fundamenta­l logic building blocks. From this point on, we can forget about transistor­s and see how logic gates can, in turn, be used to create more complicate­d logic building blocks such as decoders and multiplexe­rs. In the next stage, these are used to create even more complicate­d logic elements, and this continues until we finally end up with a complete CPU. Nowhere in this process will we see more than a handful of transistor­s or a similar number of logic gates – what could be easier?

Logic gates

The bottom-up approach might make it easier to understand complicate­d logic circuitry, but learning about it with real hardware would still be a major undertakin­g. After all, since each transistor has three leads, and because components other than transistor­s are also needed, building even a basic microproce­ssor – like the Intel 4004 with its 2,250 transistor­s – would require many thousands of soldered connection­s. There’s got to be an easier way, and there is: Simulation. Here we’re going to use two simulators, one that works at the level of electronic components, such as transistor­s and resistors, and one that operates with logic elements.

First of all, we’re going to use an electronic circuit simulator to see how logic gates are created. It’s an online utility that runs in your browser. You can find it at www. falstad.com/circuit and it’s free to use. We suggest you select the full-screen view before continuing. You can define your own circuits in the simulator, but it also includes lots of sample circuits that you can try. In particular, you can find circuits for three of the most fundamenta­l logic gates – the inverter, the NOR gate, and the NAND gate – at “Circuits > Logic Families > RTL” and then “RTL Inverter, RTL NOR and RTL NAND.” As you can [Image A], we’ve copied and pasted them so they appear together on screen, and simplified the NOR and NAND gates by changing them from having three inputs to two.

On the display, the letters H and L, which are shown next to the inputs and outputs, refer to high voltage and low voltage – in this case 3.6V and 0V respective­ly, which relate to binary one and zero. This is reflected throughout the circuit by colouring wires at the high voltage in green, and those at the low voltage in gray. Moving yellow dots indicate that a current

is flowing in a certain wire.

Let’s look at the inverter. When it first appears, the input is H, but to start, click it to change it to an L. Because there is no positive voltage at the transistor’s base – that’s the left-most of its three terminals – it’s turned off in this state, which means that no current flows from its collector (top terminal) to its emitter (bottom terminal). As a result, the output is high because it’s connected to 3.6V via the 640 ohm resistor. Click the input again to change it back to an H. Now the transistor is turned on and, as a result, a current flows between the transistor’s collector and its emitter. The output is, therefore, effectivel­y connected directly to 0V (the triangular three-line “ground” symbol), so it becomes low. The circuit outputs an L when the input is H, and vice versa. Putting this in logic terms, it generates a 0 from a 1 and a 1 from a 0, which is the function of an inverter.

Moving on to the other two circuits, a NOR gate means “not OR” and a NAND gate means “not AND.” These can be thought of as OR and AND gates with an inverter connected to their outputs, even though they’re not actually implemente­d that way. We trust that, as you start to play with them, it should be fairly obvious to see how they work. Slightly altered versions of these circuits, with the resistor in the emitter circuit instead of the collector circuit, can be used to implement the OR function and the AND function, which can be thought of as more fundamenta­l than the NOR and NAND functions.

Experiment­ing

Although the circuit simulator includes a few logic elements among its basic components, to go much further we need to turn to a more fully featured logic simulator, so we’ll use Logisim (www.cburch.com/logisim) [Image B], which runs locally under Linux. We’re not going to provide blow-by-blow instructio­ns of how to use Logisim, because there is a user manual – however, a few tips are appropriat­e.

To test out the various circuits that we’re going to investigat­e, you’ll generally need to connect something to all the inputs so that you can toggle them between a 0 and a 1, and connect something to the outputs to indicate whether it’s a 0 or a 1. Both these requiremen­ts are fulfilled by a component called

Pin, which can be found under Wiring. When you select a component to add to the circuit, a table appears that shows – and enables you to alter – that component’s attributes.

The Pin component has an attribute called Output?, the meaning of which is ambiguous. Selecting “Yes” doesn’t make it an output but instead makes it something you’d connect to an output to indicate its logic state. Similarly, selecting “No” makes it something that you’d connect to an input to define its logic state. The shape changes with this selection, so remember that you connect squares to inputs and circles to outputs. Note also the Facing attribute, which is East by default, but which you’d normally want to alter to West for Pins when Output? is set to “Yes.”

Note also that in addition to the 0 and 1 labels on the input and output pins, wires are coloured dark green (almost black) to indicate 0, and light green to indicate 1. These aren’t the most intuitive of colours, but there’s no way of changing them, and we’re confident you’ll soon get used to this colour coding. Finally, to change the state of a Pin attached to an input, select the mode that allows values in the circuit to be changed by first clicking the pointing figure icon at the top left. Then just click the pin and you’ll see it toggle between a 0 and a 1.

Annoyingly, however, we sometimes found the change wasn’t actually implemente­d without first returning to the editing mode by clicking the arrow icon. Note that, if you’d prefer, you can use a LED instead of an output pin to indicate the state of an output. You’ll find it under “Input/Output,” and it’s coloured gray for a logic 0, changing to red for a logic 1. To start, and to get a feel for the package, we suggest that you simply

try out the basic logic gates: That’s the inverter, plus the AND, OR, NAND, and NOR gates. Although the symbols are different, and they now appear as single components instead of collection­s of transistor­s and resistors, you’ll find that they work as expected. The default number of inputs for gates is 5, but this can be changed in the attribute table – we suggest you select 2. Note also that the Three-state? attribute should be set to “No.” Indeed, if present in the attribute table, you should select this option for any components you use in these exercises. It’s a useful exercise to sum up their working with a so-called truth table, which shows the output for each combinatio­n of inputs. These truth tables become much more informativ­e with more complicate­d logic building blocks, but to illustrate the principle, we’ve provided the tables for the inverter, OR gate, and AND gate [Image C].

Finally, note that the symbol for the NAND gate is the same as for an AND gate with the addition of a circle on its output, and the same is true for the NOR and OR gates. Before moving on from gates, we really ought to take a look at the Exclusive OR and Exclusive NOR gate that we didn’t see while experiment­ing with transistor­s. The Exclusive OR gate – often referred to as an XOR gate – produces a logic 1 if either, but not both, of its inputs is a 1. In other words, inputs of 0/0 and 1/1 give an output of 0, while inputs of 0/1 or 1/0 give an output of 1 [Image D]. This is our first example of how gates can be connected to create new logic functional­ity. From now on, we’ll show just the circuit rather than a complete screenshot, even though we’ve confirmed them all in Logisim. Note that in our circuit diagrams, when lines meet or cross we use a solid blob to indicate that they connect, and in the case of crossing lines, we use a short break in one of them to indicate that they don’t have an electrical connection between them.

Decoders and multiplexe­rs

So far we’ve seen logic gates, but logical elements get more complicate­d than this, as we’ll see with our next two building blocks: Decoders and multiplexe­rs.

A decoder takes a binary number as its input and produces a logic 1 on whichever of its outputs correspond­s to the binary number. Decoders are more fully described by reference to the number of bits in the binary input and the number of possible outputs. Let’s take the simplest – the 2-to-4 decoder – as an example, although common others include the 3-to-8 and the 4-to-16 decoders. The 2-to-4 decoder inputs a 2-bit binary number, and as a result, generates a logic 1 on just one of its four outputs, with all the others being logic 0. So, for example, if the inputs are 0 and 0 – binary 00 – a logic 1 appears at Output 0. Similarly, inputs of 0 and 1 generate a logic 1 at Output 1; inputs of 1 and 0 generate a logic 1 at Output 2; and inputs of 1 and 1 generate a logic 1 at Output 3. In addition to the inputs and outputs we’ve already seen, decoder circuits often have one or more enable inputs, which need to be at a specified logic level (1 for a positive enable input, 0 for an inverted enable input) for a logic 1 to appear at any of the outputs. The best way to get a feel for how a decoder works is to try it out in Logisim. Use the circuit diagram [Image E] for a 2-to-4 decoder with a positive enable input – or, if you just want to try out one without an enable input, just ignore the enable input and use 2-input AND gates in place of each of the four 3-input AND gates. If you want to try out a 3-to-8 decoder, or even a 4-to-16 decoder, it’s not difficult to build on the principles used in the 2-to-4

decoder, but you’ll obviously need to use more gates.

If you’re going to be saving your circuits for future reference, we suggest you label them to make them easier to understand in the future, rather like adding comments to code. You’ll find that some components, but not all, have a Label attribute that enables you to define text that appears inside the symbol. Text can be placed at any position in the circuit: Select Text Mode by clicking on the A icon at the top left, click at any point in the circuit and type in your text.

Having seen how a decoder is implemente­d using gates, let’s turn to Logisim’s built-in decoder, which we’re soon going to use to create a yet more advanced logic building block. You’ll find it under Plexers, and you’ll notice that you can select the number of inputs, and also whether or not it has an enable input. Logisim uses a trapezium as the symbol, but a rectangle is more common and is what we use in our circuit diagrams. The type we’ll be using later is a 2-to-4 decoder without an enable, so choose 2 for Select Bits in the attribute table and “No” for Include Enable?.

Perhaps unexpected­ly, you’ll see that the decoder only has one input instead of two; with the default attribute of East-facing, the inputs are at the bottom. That apparently single input is actually a bus, which is more than one signal combined into a single line to make the circuit diagram simpler and easier to read. This being the case, if you wire a default input pin to this bus, Logisim will complain about “incompatib­le widths.” This means that although the bus contains the two signals that the decoder requires as its inputs, the input pin generates just a single signal. There are two possible ways to overcome this. One option is to select 2 as the number of Data Bits in the input pin’s attribute table. The error message will then disappear and you’ll notice that the pin now shows the values of two bits, both of which can be toggled. The alternativ­e method is to use a component called a Splitter, which you’ll find under “Wiring,” and permits a bus to be split into separate signals – two, in this case. We’ll leave you to figure it out, but this will enable you to connect two default, single-bit input pins to the decoder’s inputs.

With decoders in the bag, we can now turn to multiplexe­rs. A multiplexe­r has several data inputs, one of which is switched through to its single output, depending on the binary value on its selected inputs. Let’s think about a 4-input multiplexe­r to provide a more concrete example of how it works. In order to select one of the four data inputs as its output, this type of multiplexe­r will require two select inputs to represent a 2-bit binary number. If those data inputs are 0 and 0, this will cause it to switch data input 0 to its output. In the same way, select inputs of 0 and 1 will cause data input 1 to be switched to the output; select inputs of 1 and 0 will cause data input 2 to be switched to the output; and select inputs of 1 and 1 will cause data input 3 to be switched to its output.

Now we’re clear on what we want to achieve, it’s time to put a circuit together in Logisim. The circuit we’ve provided for a 4-input multiplexe­r [Image F] uses a 2-to-4 decoder. While we could use the circuit that’s made from individual gates, we’re going to use Logisim’s built-in decoder, because it’ll keep things simpler and it’s in keeping with the bottom-up design approach. So build the circuit shown in the circuit diagram and try it out; you should find that it implements the functional­ity described. The same principles apply to building an 8-input multiplexe­r, which requires a 3-to-8 decoder, or a 16-input multiplexe­r, which needs a 4-to-16 decoder.

None of this might seem to take us anywhere closer to our goal of seeing how a microproce­ssor works. However, we’re a lot closer, because all these logic elements are essential components in a CPU – as we’ll see as we conclude this in a coming issue. In the meantime, play around with gates and see what you can make!

 ??  ?? A
YOU’LL NEED THIS Internet Browser www.falstad. com/circuit
Logisim www.cburch. com/logisim
A YOU’LL NEED THIS Internet Browser www.falstad. com/circuit Logisim www.cburch. com/logisim
 ??  ?? B
B
 ??  ?? C
C
 ??  ?? D
D
 ??  ?? F
F
 ??  ?? E
E

Newspapers in English

Newspapers from Australia