# Project 1

#### Get the software

Figure out how to run the HardwareSimulator. The Software page and the Project 1 page on the Nand2tetris website have more details and links to the relevant documentation. If you are stuck, ask on Piazza, or—in the worst case—come to my office.

For this and the following projects, you may find the HDL Survival Guide useful.

#### Which food to serve?

A logician walks into a restaurant and tells the owner:

1. I eat potatoes or noodles, but not both together;
2. If I eat potatoes, then I eat no bread; and
3. If I eat bread or no potatoes, then I don't eat noodles.
What should the poor restaurant owner serve the logician?

Each of the three conditions is a Boolean function of the three variables potatoes, noodles, and bread. It is true if the condition holds.

Design a circuit Food that has three inputs potatoes, noodles, and bread, and three outputs cond1, cond2, cond3 for the three conditions.

// Project #1-a
//
// Design a circuit to check the three conditions
//
// Use built-in gates Not, And, Or, Nand, Xor.
//

CHIP Food {
OUT cond1, cond2, cond3;

PARTS:
}

You can use the built-in gates Not, And, Or, Nand, and Xor.

Use the script Food.tst to load the circuit and evaluate it for all possible outputs. The script will write an output file Food.out.

Here are a few lines from Food.out:

|potatoe|noodles| bread | cond1 | cond2 | cond3 |
|   0   |   0   |   0   |   0   |   1   |   1   |
|   1   |   0   |   1   |   1   |   0   |   1   |
|   1   |   1   |   1   |   0   |   0   |   0   |

(The other lines are missing to make the project more interesting...)

As you can see, if neither potatoes, noodles, or bread are served, then only the first condition is violated. If potatoes and bread are served, then the second condition is violated. And if all three are served, then all three conditions are violated.

Your output file should tell you what the restaurant owner must do.

#### Submitting the project

You have to register with your student id the first time you use the server.

When you register, you have to choose an alias. This alias will be used when I post your homework and exam scores.

You must remember your password. There is currently no way to retrieve or change your password. (In the worst case I can delete your registration so you can register again.)

#### And what does the logician drink?

The logician doesn't want to stay thirsty, so he tells the restaurant owner:

1. I will drink wine if there is no water;
2. If both wine and water are served, then no apple juice must be served;
3. If there is apple juice, or if there is no water, then there must be no wine.

Design a circuit Drinks with the three inputs wine, water, and juice, and the three outputs cond1, cond2, cond3.

// Project #1-b
//
// Design a circuit to check the three conditions
// about serving wine, water, or juice.
//
// Use built-in gates Not, And, Or, Nand, Xor.
//

CHIP Drinks {
IN wine, water, juice;
OUT cond1, cond2, cond3;

PARTS:

| wine  | water | juice | cond1 | cond2 | cond3 |