selecting functions

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 and B
  • Takes a third operation input, which is either marble or hole
  • If the operation is marble, calculate A + B
  • If the operation is hole, subtract A - B

So we need a way to use the operation input to select one of our devices.

challenge

How can we use the tools we’ve previously encountered to do this?

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.

00/0000/00
loading…

cloning

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.

00/0000/00
loading…

selector 2

putting it together

coming soon
We’re still working on this part of the tutorial — come back later!

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