# Lab 5: Decoding AVR Instructions¶

After reviewing the actual encoding used in the AVR processors, I worked up a spreadsheet that includes enough instructions to build some simple programs for our simulator. The encoding is not so complicated that we really need to create our own encoding, so we will use the real chip encoding scheme. This will allow us ot use the actual AVR assembler to generate sample programs for our simulator projects.

Note

This lab is to be worked on in your group. I want each team member to submit the final code in the class repository, but you can freely share code within your group.

## Basic Decoding Logic¶

The decoder receives a 16-bit instruction from the fetch unit. That instruction may be augmented by a second 16-bit constant that we will ignore for now.

Here are the input signals for this unit:

• IR1: - 16-bit instruction code

Here are the output signals to generate

• INST: binary instruction code (numbered alphabetically
• RegD: 8-bit destination register (if used)
• RegR: 8-bit source register if needed
• Const: 16-bit Constant (extended from smaller values if needed)
• IR2: just set this up as a boolean indicating we need another chunk of data. Use the lecture notes on decoding to find the pattern for this code.

You will want to use the C++ bitset class for the decoding work.
You should set up a catch.hpp test file to check your function. You can feed it sample data for each instruction, derived from the example spreadsheet provided in the lecture notes. You do not need to test with all possible registers, just a few should be fine.