Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1Learning Outcomes

To design circuits that perform complex operations on binary signals, we must first define primitive operators called logic gates. Logic gates are simple circuits (each with only a handful of transistors) that can be wired together to implement any combinational logic function. In CS 61C we consider logic gates are primitive elements; they are the basic building blocks for our circuits.

The simplest logic gates are binary or unary operators that take as input one/two binary variables and output one binary value.

2Common Logic Gates

Here are some common logic gates. For each we define its name and show (left) its graphical representation and (right) a truth table that defines its function.

AND

Gate
Truth Table
"TODO"

OR

Gate
Truth Table
"TODO"

NOT

Gate
Truth Table
"TODO"

NAND

Gate
Truth Table
"TODO"

NOR

Gate
Truth Table
"TODO"

XOR

Gate
Truth Table
"TODO"

Notes:

3N-Input Logic Gates

Except for NOT (which is a unary operator), we have shown 2-input versions of these common gates. Versions of these gates with more than two inputs also exist. For performance reasons, the number of inputs to logic gates is usually restricted to around a maximum of four.

"TODO"

Figure 15:4-input AND gate. The output y is 1 if and only if a, b, and c are all 1.

The function of these gates with more than two inputs is obvious from the function of the two input version, except in the case of the the exclusive-or gate,

Except for NOT (which is unary), we have shown 2-input versions of these gates. Versions of these gates with more than two inputs also exist. However, for performance reasons, the number of inputs to logic gates is usually restricted to around a maximum of four.

The function of these gates is generally self-evident and can deterined by repeatedly composing the equivalent 2-input gate; for example, AND(a, b, c, d) = AND(AND(a, AND(b, AND(c, d)))) = AND(AND(a, b), AND(c, d)), etc. There are a few exceptions; let’s try your reasoning with some quick checks.

4Combinational Logic Circuit \rightarrow Truth Table

Note that simple logic gates can be wired together to build useful circuits. In fact, any combinational logic block can be implemented with nothing but AND, OR, and NOT logic gates.

However, to understand what a circuit actually does, we need more than just its circuit diagram: we need a concise description of its operation. Let’s first try with truth tables.

To generate a truth-table from a given circuit, we need to evaluate it for input combinations.

So...what does this circuit do? Importantly, we note that the outputs of the two AND gates will never both be 1, so we could have replaced the OR gate with an XOR gate.

After some thought, we may realize that this combinational logic circuit may actually be succinctly described as a compare: Take two inputs and returns 1 if the two inputs are equal and 0 otherwise.

If we wanted to use this compare circuit in other circuits, we can! Just represent it as a combinational logic block, as below:

"TODO"

Figure 17:Bitwise compare circuit; a block representation of the mystery circuit in Figure 16.

5Composing Circuits: 32-Bit Comparator

We would like to a circuit that compares two 32-bit values; this 32-bit compare circuit can be used in our processor to implement the equality comparison for the RV32I instruction beq rs1 rs2 Label.

"TODO"

Figure 18:32-bit compare circuit.

Compare this new 32-bit compare circuit(Figure 18) with our previous 1-bit compare circuit (Figure 17):

Functionally, z is 1 only if all of A’s bits are equal to all of B’s bits. In other words, we can perform 32 bitwise comparisons, then AND them together. The underlying circuit for our compare block is therefore as follows:

"TODO"

Figure 19:32-bit compare circuit diagram, assuming we have implemented the bitwise compare circuit. The 32-input AND gate can be implemented recursively with 2- or 4-input AND gates.

Footnotes
  1. Mnemonic: The AND gate is shaped like the “D” in AND.

  2. Out of scope for this course, but those interested, read more about AND.

  3. Notably, this circuit is not a NAND gate; we leave the proof to you. We suggest writing things out with truth tables.