## Your task

You will make an **divider capable of dividing 16-bit numbers by 8-bit numbers** which will take **9 clock cycles** to produce the quotient.

Why 16-by-8? Well, for the same reason when you multiply two 8-bit numbers, you get a 16-bit product; since division is backwards, you

startwith a 16-bit dividend, and divide by an 8-bit divisor to get an 8-bit quotient.

Why 9 cycles? Well it would be 8 but we’re starting the divisor shifted left by 8 instead of 7, so the first cycle will be a “dummy” cycle to shift it right by one.

## 0. Starting off

First, go to the materials page and download/open the `fast_mult_4x4.circ`

example. I showed how this worked in class, so play around with it yourself.

Now, for your lab, to make it easier for the grader, **start off by placing the following near the top-left of the circuit (you can copy it from the multiplier circuit):**

This is a clock and an **Input/Output > Button** going into an OR gate, to produce the clock signal. By doing this, you can tick the clock by clicking the button *once,* instead of clicking the clock *twice.*

Finally, **make 3 16-bit registers and name them like so:**

Don’t forget to hook the clock up to the triangle inputs on these registers! Use tunnels like shown in the first pic.

Here is the algorithm you’ll implement in circuitry:

```
// you'll put these values into the registers with the poke tool.
divisor <<= 8;
remainder = dividend;
quotient = 0;
// ...and you'll tick the clock 9 times to do this loop :D
for(9 times) {
// THIS is what you'll really be implementing.
if(divisor > remainder) {
quotient = (quotient << 1) | 0; // "append a 0"
} else {
remainder = remainder - divisor;
quotient = (quotient << 1) | 1; // "append a 1"
}
divisor >>= 1;
}
```

## 1. The Divisor register

This is the easiest one.

- Put a
**probe**on the output of the divisor register set to “unsigned decimal” to make things easier to debug. **Every clock cycle, the value in the divisor register needs to be shifted right by 1.**- The
**Arithmetic > Shifter**component does bit shifting.- Its
**Shift Type**property should be “Logical Right”, since we’re dealing with unsigned numbers. - The second input is the distance to shift, which you can make a
**Wiring > Constant**- What do you notice about the*number of bits*for the second input? - Why do you think that is?

- Its
- Make sure the register has its
**clock input hooked up.**(You may as well connect the clock to the other registers too, while you’re at it.)

**To test:**

- Use the poke tool and click the value in the divisor register. Type in a value like
`1234`

. - Then,
**tick the clock**by poking the clock button with the poke tool.- You will see the value decreasing with each clock tick (dividing by 2), until it reaches 0.

## 2. The subtraction step and Dividend/Remainder register

In the code above, `remainder`

is set to `remainder - divisor`

, but *only if* `divisor <= remainder`

. **We can implement this condition using the Remainder’s write enable input.**

- Make a
**Subtractor**and have it subtract`remainder - divisor`

.- The subtractor has a
`b out`

output on the bottom. - Try putting various numbers into the Remainder and Divisor registers. What do you notice about
`b out`

?- It
**turns on (1)**when the divisor is**too big**to fit in the remainder! - Another way of thinking of
`b out`

is that it means`divisor > remainder`

.

- It

- The subtractor has a
- We only want to
*write to the Remainder register*when the divisor*does*fit in the remainder.- So you’ll have to invert
`b out`

and use that as the write enable for Remainder.

- So you’ll have to invert

**To test:**

- Put
`3e8`

in Remainder and`2100`

in Divisor. (This is`1000 ÷ 33`

; 33 is`0x21`

, but we shift it left by 8, so it becomes`2100`

.) - Click the clock button, and after a few cycles, the
**contents of the Remainder register**should go**1000, 472, 208, 76, 10.**- If your remainder register becomes
**58088**instead, you forgot to NOT the`b out`

output. **NOTE: it is totally fine and normal for the**but if you save that 58088 into the remainder register,*subtractor*to output 58088;**that is a mistake.**

- If your remainder register becomes

## 3. The Quotient register

Last is the quotient. You’re on your own for this one.

- Although the
`quotient = ...`

lines are inside the`if-else`

, the quotient is*always*changed, so it’s**not**gonna need a write enable. - The basic idea is
`quotient = (quotient << 1) | something`

, where`something`

is 0 or 1 based on the condition from the last step, right? - Don’t forget, you can do OR with an OR gate; change its “Data Bits” to 16.

**To test:**

- Let’s try
`1000 ÷ 33`

again; put`3e8`

in remainder and`2100`

in divisor. Make sure quotient is 0. - Tick the clock 9 times.
- Now quotient should be 30 and remainder should be 10!

Try it with some other numbers.

## Submitting

Once you’re sure your circuit works, you can submit.

**Name your circuit file username_lab6.circ, like jfb42_lab6.circ.**

Drag your asm file into your browser to upload. **If you can see your file, you uploaded it correctly!**

You can also re-upload if you made a mistake and need to fix it.