# HW7: Defining the ALU Component¶

This homework is about teaching the machine to do simple math.

## Defining the ALU¶

In this homework, we will define the basic ALU functions we need for our simple machine. We will do this by examining the instructions provided by the `attiny85`.

You will need the processor data sheetL

Look in the Instruction Set Reference section of this document, and list all of the instructions that perform basic arithmetic and logic functions.

Your list should in in the form of a table like this:

Mnemonic Operands Operation FLAGS Clocks
ADD Rd,Rr Rd <- Rd + Rr Z,C,N,V,H 1

Note

You need to look at the reStructuredText markup used to build this table by looking at the source for this page using the link on the left side of this page.

From this list, identify the math functions we need to provide. For each operation, there is a set of “FLAGS” listed that need to be calculated in order to provide Status information about what happened when the operation was performed. You will need to look in the documentation to define each flag, and what each flag means.

## Create an Initial ALU Class¶

Based on your research, create a skeleton ALU class for the simulator. Remember that the ALU will be responding to “signals” of the sort we have been building in our `attiny85sim` project. Your class will respond to a “tick” function, and examine inputs and generate outputs. For now, you do not need to worry about the pointer interface we will use, we will be designing that in our next few lab projects. Just set up normal C++ methods like this:

• `get_op1()`
• get_op2()``
• get_status()``

That last function needs a bit of explanation. We will generate a set of flag bits, and “pack” them into a single byte for output. We will be using the `bitset` template class for this. You can assume we will have a private function named `pack_status()` to create this byte for output. See Determining Carry and Overflow FLags for notes on some of the calculations we will need for thes status bits.

Your code should compile, but it does not need to run. We will fill in the details later.

Place this work in a HW7 folder under the `homework` folder in your simulator project repository.