We’ve now seen how to build an adder and a subtractor. Now let’s look at integrating them into a single device.
goal
We want a device that:
- Takes in two numbers
A
andB
- Takes a third operation input, which is either
or
- If the operation is
, calculate
A + B
- If the operation is
, subtract
A - B
So we need a way to use the operation input to select one of our devices.
solution
Let’s look at two approaches that share a common core.
The first insight is that we can send the data to both devices, and then select the output from the operation that we want.
We achieve this by cloning A
and B
, and sending a copy of each to the adder and subtractor.
The second step is to select the appropriate output, and discard the output from the other device. There are two approaches here:
- Use a selector to pick the output stream we want
- Put the outputs consecutively into a looped register, then use a timer to pick out the appropriate device
The timer approach might be easier to extend if we add more devices later — we can just make the register bigger. But for our simplified case, let’s just use a selector.
putting it together
next
Now our patterns can dynamically select what operation to perform. In the next tutorial, we’ll explore how to use this capability to build a computer.
continue