Truth Table Program

The Truth Table Program

One way to implement a combinational circuit from a truth table is by using a PROM (Programmable Read Only Memory). This can be done by generating a HEX file from a program called truth_table, and then using the HEX file to program a PROM.

The truth_table program is in a wiliki directory ~ee260/bin. Therefore, you should have a "path" in your .cshrc file as:

```set path=(\$path ~ee260/bin)
```
If you have just changed your .cshrc file, be sure to log out and then log in again to reset your environment properly.

To run the truth_table program, just type:

```truth_table
```

To facilitate the discussion a little more, let's assume that we would like to program a PROM, that is to be used in a sequential circuit. The sequential circuit has the following state transition table:

```
Present         |  Next
State    Input |  State   Output
Q1  Q0      X   | Q1+ Q0+    Y
------------------+-----------------
0   0      0   |  0   0     0
0   0      1   |  0   1     0
0   1      0   |  0   0     1
0   1      1   |  1   0     1
1   0      x   |  1   1     0
1   1      0   |  0   0     1
1   1      1   |  0   1     0

```

Thus, we would like to program a 3 input and 3 output PROM so that it has the following truth table:

```   a2  a1  a0   | d2  d1  d0
---------------+---------------
0   0   0   |  0   0   0
0   0   1   |  0   1   0
0   1   0   |  0   0   1
0   1   1   |  1   0   1
1   0   x   |  1   1   0
1   1   0   |  0   0   1
1   1   1   |  0   1   0

```
Note that inputs a2, a1, and a0 correspond to Q1, Q0, and X, respectively, and that outputs d2, d1, and d0 correspond to Q1+, Q0+, and Y, respectively.

Now, let's turn our attention back to running truth_table. After starting truth_table, you will get the following menu:

```
n - New Table

h - Load Hex File into Table

e - Edit Current Table

? - Help

q - Quit
```

At this point, the program is looking for data for a truth table.

• n will start a fresh new truth table.
• l will load data from an old truth table that's been stored as a file. The data is stored in a particular format we'll call the truth_table data format, which will be discussed later.
• h will load data from an old truth table that's been stored as a file, but in the HEX format. We will give an example of this kind of file later.
• e allows editing of the current table in the program (if one exists).
• ? will get a help menu.
• q will get you out of the program.

Let's proceed by typing n to start a new truth table. The program will ask you the number of inputs and outputs for the truth table. For the example above, you should enter 3 for both.

Now a truth table will appear on your screen with inputs (a2,a1,a0) and outputs (d2,d1,d0). You can now enter Os, 1s, and xs into the table, by moving the cursor around and typing in the 0, 1, or x. To move the cursor around, you can use the arrow buttons, which are usually at the bottom right of most keyboards. Another way to move the cursor is to use the keys

• h: to move left
• k: to move up
• l: to move right
• j: to move down
There's also a list of commands at the bottom of the screen, which shows how the h, k, l, and j can be used to move the cursor around.

After filling in the table, you may save the data in two forms: in the truth_table data format or in the HEX format. Typing s will save the data in the truth_table data format. The program will ask you for the name that you wish the file to be saved as, and will notify you if it has saved it successfully.

Typing H will save the data in the HEX format. The program will ask you for the name that you wish the file to be saved as. The file name must have a .HEX suffix (don't forget to capalize HEX), for example, filename.HEX. If you forget the suffix, the program will ask for another name.

You can then type q to get out of the program.

The difference the two formats is that truth_table data format can store "don't cares" (i.e, xs), while the HEX format can only store 0s and 1s. So for the truth_table data format, the truth table can be stored exactly as you typed it. Whereas for the HEX data format, the data that you typed must be converted to 0s and 1s before storing. Hence, it's advantageous to store data in the truth_table data format because it preserves the original truth table.

In the Appendix below are two files for the truth table in the two formats. You can see the file in the truth_table data format by clicking here. To see the file in the HEX format, clickhere. It's not important for you to understand the formats, but just to know that they are different.

Now the HEX file that results from the truth_table program looks something like this (with the most of it snipped off):

```INPUT               a2 0 0 0
INPUT               a1 0 0 0
INPUT               a0 0 0 0
OUTPUT              d2 0 0 0 0 0
OUTPUT              d1 0 0 0 0 0
OUTPUT              d0 0 0 0 0 0
HEX
:10000000f8faf9fdfefef9faffffffffffffffff21
:10001000fffffffffffffffffffffffffffffffff0
:10002000ffffffffffffffffffffffffffffffffe0
:10003000ffffffffffffffffffffffffffffffffd0
:10004000ffffffffffffffffffffffffffffffffc0
:10005000ffffffffffffffffffffffffffffffffb0
:10006000ffffffffffffffffffffffffffffffffa0
:10007000ffffffffffffffffffffffffffffffff90
:10008000ffffffffffffffffffffffffffffffff80
:10009000ffffffffffffffffffffffffffffffff70
:1000a000ffffffffffffffffffffffffffffffff60

(snipped a bunch of stuff here)
```
This file cannot be used to program PROMs. It has to be "edited" to strip away extraneous information, and in particular the lines that do not start with colons must be removed. The lines with colons have all the data of the truth table. To remove the extraneous lines, use an editor such as vi. For the example above, the following lines should be deleted:
```INPUT               a2 0 0 0
INPUT               a1 0 0 0
INPUT               a0 0 0 0
OUTPUT              d2 0 0 0 0 0
OUTPUT              d1 0 0 0 0 0
OUTPUT              d0 0 0 0 0 0
HEX
```

This leaves the following HEX file, which can be used to program PROMs:

```:10000000f8faf9fdfefef9faffffffffffffffff21
:10001000fffffffffffffffffffffffffffffffff0
:10002000ffffffffffffffffffffffffffffffffe0
:10003000ffffffffffffffffffffffffffffffffd0
:10004000ffffffffffffffffffffffffffffffffc0
:10005000ffffffffffffffffffffffffffffffffb0
:10006000ffffffffffffffffffffffffffffffffa0
:10007000ffffffffffffffffffffffffffffffff90
:10008000ffffffffffffffffffffffffffffffff80
:10009000ffffffffffffffffffffffffffffffff70
:1000a000ffffffffffffffffffffffffffffffff60

(snipped a bunch of stuff here)
```

Appendix: Example Data Files From truth_table

An example file in the truth_table data format:
```-------------------------------- OUTPUT FILE -------------------------------

| abc || ABC |
| 000 || 000 |
| 001 || 010 |
| 010 || 001 |
| 011 || 101 |
| 10x || 110 |
| 110 || 001 |
| 111 || 010 |

INPUTS:
a => a2
b => a1
c => a0

OUTPUTS:
A => d2
B => d1
C => d0
----------------------------------------------------------------------------

NOTE: IF YOU WANT TO LOAD TABLE BACK IN
DO NOT CHANGE FORMAT ABOVE
----------------------------------------------------------------------------
```

An example file in the HEX format (long -- many lines):

```INPUT               a2 0 0 0
INPUT               a1 0 0 0
INPUT               a0 0 0 0
OUTPUT              d2 0 0 0 0 0
OUTPUT              d1 0 0 0 0 0
OUTPUT              d0 0 0 0 0 0
HEX
:10000000f8faf9fdfefef9faffffffffffffffff21
:10001000fffffffffffffffffffffffffffffffff0
:10002000ffffffffffffffffffffffffffffffffe0
:10003000ffffffffffffffffffffffffffffffffd0
:10004000ffffffffffffffffffffffffffffffffc0
:10005000ffffffffffffffffffffffffffffffffb0
:10006000ffffffffffffffffffffffffffffffffa0
:10007000ffffffffffffffffffffffffffffffff90
:10008000ffffffffffffffffffffffffffffffff80
:10009000ffffffffffffffffffffffffffffffff70
:1000a000ffffffffffffffffffffffffffffffff60
:1000b000ffffffffffffffffffffffffffffffff50
:1000c000ffffffffffffffffffffffffffffffff40
:1000d000ffffffffffffffffffffffffffffffff30
:1000e000ffffffffffffffffffffffffffffffff20
:1000f000ffffffffffffffffffffffffffffffff10
:10010000ffffffffffffffffffffffffffffffffff
:10011000ffffffffffffffffffffffffffffffffef
:10012000ffffffffffffffffffffffffffffffffdf
:10013000ffffffffffffffffffffffffffffffffcf
:10014000ffffffffffffffffffffffffffffffffbf
:10015000ffffffffffffffffffffffffffffffffaf
:10016000ffffffffffffffffffffffffffffffff9f
:10017000ffffffffffffffffffffffffffffffff8f
:10018000ffffffffffffffffffffffffffffffff7f
:10019000ffffffffffffffffffffffffffffffff6f
:1001a000ffffffffffffffffffffffffffffffff5f
:1001b000ffffffffffffffffffffffffffffffff4f
:1001c000ffffffffffffffffffffffffffffffff3f
:1001d000ffffffffffffffffffffffffffffffff2f
:1001e000ffffffffffffffffffffffffffffffff1f
:1001f000ffffffffffffffffffffffffffffffff0f
:10020000fffffffffffffffffffffffffffffffffe
:10021000ffffffffffffffffffffffffffffffffee
:10022000ffffffffffffffffffffffffffffffffde
:10023000ffffffffffffffffffffffffffffffffce
:10024000ffffffffffffffffffffffffffffffffbe
:10025000ffffffffffffffffffffffffffffffffae
:10026000ffffffffffffffffffffffffffffffff9e
:10027000ffffffffffffffffffffffffffffffff8e
:10028000ffffffffffffffffffffffffffffffff7e
:10029000ffffffffffffffffffffffffffffffff6e
:1002a000ffffffffffffffffffffffffffffffff5e
:1002b000ffffffffffffffffffffffffffffffff4e
:1002c000ffffffffffffffffffffffffffffffff3e
:1002d000ffffffffffffffffffffffffffffffff2e
:1002e000ffffffffffffffffffffffffffffffff1e
:1002f000ffffffffffffffffffffffffffffffff0e
:10030000fffffffffffffffffffffffffffffffffd
:10031000ffffffffffffffffffffffffffffffffed
:10032000ffffffffffffffffffffffffffffffffdd
:10033000ffffffffffffffffffffffffffffffffcd
:10034000ffffffffffffffffffffffffffffffffbd
:10036000ffffffffffffffffffffffffffffffff9d
:10037000ffffffffffffffffffffffffffffffff8d
:10038000ffffffffffffffffffffffffffffffff7d
:10039000ffffffffffffffffffffffffffffffff6d
:1003a000ffffffffffffffffffffffffffffffff5d
:1003b000ffffffffffffffffffffffffffffffff4d
:1003c000ffffffffffffffffffffffffffffffff3d
:1003d000ffffffffffffffffffffffffffffffff2d
:1003e000ffffffffffffffffffffffffffffffff1d
:1003f000ffffffffffffffffffffffffffffffff0d
:10040000fffffffffffffffffffffffffffffffffc
:10041000ffffffffffffffffffffffffffffffffec
:10042000ffffffffffffffffffffffffffffffffdc
:10043000ffffffffffffffffffffffffffffffffcc
:10044000ffffffffffffffffffffffffffffffffbc
:10045000ffffffffffffffffffffffffffffffffac
:10046000ffffffffffffffffffffffffffffffff9c
:10047000ffffffffffffffffffffffffffffffff8c
:10048000ffffffffffffffffffffffffffffffff7c
:10049000ffffffffffffffffffffffffffffffff6c
:1004a000ffffffffffffffffffffffffffffffff5c
:1004b000ffffffffffffffffffffffffffffffff4c
:1004c000ffffffffffffffffffffffffffffffff3c
:1004d000ffffffffffffffffffffffffffffffff2c
:1004e000ffffffffffffffffffffffffffffffff1c
:1004f000ffffffffffffffffffffffffffffffff0c
:10050000fffffffffffffffffffffffffffffffffb
:10051000ffffffffffffffffffffffffffffffffeb
:10052000ffffffffffffffffffffffffffffffffdb
:10053000ffffffffffffffffffffffffffffffffcb
:10054000ffffffffffffffffffffffffffffffffbb
:10055000ffffffffffffffffffffffffffffffffab
:10056000ffffffffffffffffffffffffffffffff9b
:10057000ffffffffffffffffffffffffffffffff8b
:10058000ffffffffffffffffffffffffffffffff7b
:10059000ffffffffffffffffffffffffffffffff6b
:1005a000ffffffffffffffffffffffffffffffff5b
:1005b000ffffffffffffffffffffffffffffffff4b
:1005c000ffffffffffffffffffffffffffffffff3b
:1005d000ffffffffffffffffffffffffffffffff2b
:1005e000ffffffffffffffffffffffffffffffff1b
:1005f000ffffffffffffffffffffffffffffffff0b
:10060000fffffffffffffffffffffffffffffffffa
:10061000ffffffffffffffffffffffffffffffffea
:10062000ffffffffffffffffffffffffffffffffda
:10063000ffffffffffffffffffffffffffffffffca
:10064000ffffffffffffffffffffffffffffffffba
:10065000ffffffffffffffffffffffffffffffffaa
:10066000ffffffffffffffffffffffffffffffff9a
:10067000ffffffffffffffffffffffffffffffff8a
:10068000ffffffffffffffffffffffffffffffff7a
:10069000ffffffffffffffffffffffffffffffff6a
:1006a000ffffffffffffffffffffffffffffffff5a
:1006b000ffffffffffffffffffffffffffffffff4a
:1006c000ffffffffffffffffffffffffffffffff3a
:1006d000ffffffffffffffffffffffffffffffff2a
:1006e000ffffffffffffffffffffffffffffffff1a
:1006f000ffffffffffffffffffffffffffffffff0a
:10070000fffffffffffffffffffffffffffffffff9
:10071000ffffffffffffffffffffffffffffffffe9
:10072000ffffffffffffffffffffffffffffffffd9
:10073000ffffffffffffffffffffffffffffffffc9
:10074000ffffffffffffffffffffffffffffffffb9
:10075000ffffffffffffffffffffffffffffffffa9
:10076000ffffffffffffffffffffffffffffffff99
:10077000ffffffffffffffffffffffffffffffff89
:10078000ffffffffffffffffffffffffffffffff79
:10079000ffffffffffffffffffffffffffffffff69
:1007a000ffffffffffffffffffffffffffffffff59
:1007b000ffffffffffffffffffffffffffffffff49
:1007c000ffffffffffffffffffffffffffffffff39
:1007d000ffffffffffffffffffffffffffffffff29
:1007e000ffffffffffffffffffffffffffffffff19
:1007f000ffffffffffffffffffffffffffffffff09
:00000001
```