Exam 2 Review¶
Read time: 22 minutes (5658 words)
Here are the major topics we covered since the last exam. Note that some things dealing with C++ programming are not considered part of the testable material!
Moving Data¶
We looked at the most significant thing you need to know about how machines work. They simply move data between a bunch of components that process any signals coming their way. The timing of all of this is controlled by a control unit, but basically, the machine is just a simple bunch of relatively simple digital parts linked by wires.
- Creating Components - generic class with basic parts
Simple Registers - no processing, just hold data
Input set - one or more input signal lines
Output set - one or more output signal lines
Tick - makes things happen
- Creating Wires - used to transfer data between components
single Input - only one signal can drive a wire
Multiple outputs - a wire can drive more than one output
Tock? - makes the data move along the wire
We can design our systems by thinking through how data will flow through the machine. A simple notation called “Register Transfer Language” (RTL) is commonly used for this:
Register Transfer Language - used to describe what we need to happen * Notation is simple: “source_reg -> destination_reg” describes movement along a wire!
Simulator¶
A simulator seeks to model how a real machine works. To build one we need to model each part in the machine, and model how data moves around in that machine. We set out to do this with a few fairly simple C++ classes and used inheritance to build custom parts. We used digital wires to move data from part to part, and used simple methods to tell each internal part when to do whatever it was trained to do!
- Basic Parts - derived from base component class
Memory - where data can be saved * Read-only memory (Instruction memory unit: IM) * Read/Write memory: Data memory (Data memory unit: DM) * Two-port read/ One port write (Register File: RF)
- Registers - internal and very fast
Designed to feed the ALU, so two outputs at a time are generated.
ALU - used for processing data using arithmetic and logic
Multiplexor - selects one of several possible sources, Used to gate signals as they move along
Fetch Unit¶
Instruction processing begins with the fetch unit. This part accesses
instruction memory using a simple program counter
(PC) which holds the
address of the next instruction to process. That address is routed to the
instruction memory and the next instruction is fetched and passed along.
(We actually fetched two instruction items, in case two are actually needed.)
- Parts Needed
PC - tracks next instruction
IM - instructions to fetch
IR = current instruction fetched
Decode Unit¶
Once the instruction reached the decoder, it is checked, and broken up into usable fields which control aspects of the rest of the machine. If needed, the decoder will get more data from IM in case the first chunk fetched is not a complete instruction.
The decoder is also responsible for updating the PC if needed.
- Parts Needed
- Decode logic = break an instruction up into fields
constants
Register selectors
Other control bits
- Internal Registers - usually only a few, but they are fast!
In our machine, up to two registers can be delivered to the next stage
- Additional data from IM? - Decode may need to go back and fetch more from IM
We avoided that by “pre-fetching” the posible second item from IM
- Updating the PC
Normal sequencing - add instruction size to PC and store it back
Branch control - if we branch, we need to change the PC storing the new address
Instruction Set Architecture¶
Most machines are designed based on the need to do some kind of processing. Designers study how the users plan on using the machine, and come up with instructions to make it easy to get their job done.
- Designing a machine based on instructions
Study sample code!
Invent instruction that make processing high level code easier.
Use RTL to describe each instruction
Derive machine from RTL
- Packing instructions to save space in IM
Decoding gets harder
- Binary “code” needs to be loaded into the machine’s memory modules
Intel HEX files - used to store binary data for microcontrolers
Memory Unit¶
We store data in several places in a modern machine. Each memory unit we need can be custom tuned for its intended purpose.
- Array of cells
Register memory is designed to allow reading two data items at one time for speed.
usually bytes, but may be bigger for instructions
- Control lines needed
Address - which “index” (address) will we access.
Data in - incoming data for writes (if needed)
Data out - outgoing data for reads
R/W signal - which operation are we doing
Tick - do the action
Execute Unit¶
This is where data is manipulated, generating new results. For some operations, no processing is needed, so signals may pass through unmodified.
- Parts Needed
ALU - to process data
- MUX to select inputs for processing in the ALU
Registers -
immediate data
PC for relative branch instructions
Store¶
This is where the data memory lives. Some instructions will write data into the DM. Other instructions may not access this memory at all (storing data back in registers.
Input/Output¶
A special kind of memory is common in the world of processors. Although the memory looks like normal read/write memory to the programmer, what actually happens in each memory cell is quite different. Each bit within the memory call is connected physically to a pin on the chip that cna be physically attached to a piece of hardware. We need to connect physical input signals to an input pin, and output signals to an output pin, but this is easy to figure out. The AVR chip is neat in that you can decide what direction the pin needs to be under software control, and even change it while a program is running. Ther are gadgets out there that work this way!
When you read an I/O memory location, you are accessing the current signals on the designated input pins, reading signals coming from attached physical devices. This is how we access sensors, which measure something from the outside world. When we write into an I/O location, we are providing a digital signal that will be passed to an attached output device to make something happen in the outside world. Typical applications include turning on (or off) lights, or activating a motor.
Microcontrollers are designed to interact with our human world, so there are an amazing number of gadgets we can hook up to out computers and writeprograms to make things happen. That is what “embedded computing” is all about!