Download presentation
Presentation is loading. Please wait.
1
FSMs, Multiplication, and Division
CS/COE 0447 Jarrett Billingsley
2
Class announcements what IS project 2 idfk CS447
3
Finite State Machines CS447
4
What's an FSM? a Finite State Machine is a machine with a finite number of states. :^) lol jk it's a way of thinking about a sequential process where: there are inputs which can change the state the system has a state (memory) there are outputs based on the state (and maybe on the inputs) should panic? bears seen: 3 bears seen: 2 bears seen: 0 bears seen: 1 yeah ok nah - FSMs come up all the time in programming and hardware design - they're great for controlling simple multiple-step procedures - FSMs are easy to reason about and transform (take CS1511) - by breaking up more complex things into interdependent FSMs you can make it easier to think about your program/circuit CS447
5
Are flip-flops FSMs? I guess?
they're like the simplest possible ones... but it's not really important :B - I just made this slide cause I almost always get this question… CS447
6
A very simple example off high med low
what states can a ceiling fan be in? high, medium, low, and off what are the input and output? the chain and the motor when you pull the chain, it changes state pull pull pull off high med low pull - I don't really know why they go high, medium, low, but they do. - unless it's the one in our bedroom. then it goes medium, medium, low, off. something's broken… CS447
7
Missing some arrows off high med low
at any point in time, which of 2 choices can the input (chain) be? pulled or not-pulled when you don't pull the chain, what happens? off high med low pull no pull no pull no pull no pull this is the full state transition diagram - sometimes we just leave those "stay-in-the-same-state" arrows off, though, to say "if none of the conditions are satisfied, don't change" - but that can get you into trouble - did you mean to stay in the same state? or did you just forget a possibility? every state should be able to handle every input! CS447
8
Table-a-fying it S In Snext off 1 hi med low off hi hi med med low low
we can represent this diagram with a table: S In Snext off 1 hi med low off high med low pull no off hi hi med for the input, let's say: 0 means not pulling 1 means pulling med low low off CS447
9
State off hi med low Motor power 0% 100% 50% 25%
What about the outputs? our fan controller has to control the motor after all we can make a table showing the output(s) for each state note that the input isn't needed at all in this case. State off hi med low Motor power 0% 100% 50% 25% this is a Moore Machine. Mealy Machines let the output depend on the state and inputs. the outputs only depend on the current state! - we'll mostly stick with Moore machines, but sometimes a Mealy machine is more elegant. depends on the situation! CS447
10
Making a circuit out of it
this is a sequential circuit – the state changes over time but the state transition and output tables are combinational here's the general organization of any Moore FSM circuit: state feeds back into transition logic outputs based on state transition logic inputs output logic outputs D Q state register - this pattern is gonna come up over and over as we design circuits… - this is basically how all sequential and combinational circuits come together! CS447
11
Kinds of FSMs CS447
12
Counters 0 bears 1 bear 2 bears ≥3 bears
counters just count how many of something they've "seen" usually the states form a ring (like the ceiling fan) sometimes they make a line: 0 bears 1 bear 2 bears ≥3 bears bear or cat in this machine, there's no way to "get back" to an earlier state. - that can get real annoying real fast, if you want to count up to large numbers. - but sometimes you need to keep track of a number, and it doesn't have to be part of the FSM itself… there are also as many states as numbers you want to represent… CS447
13
this is kind of a generator-counter combo.
Generators sometimes you have no inputs other than some signal to tell you to go to the next step (what's that signal called?) these are useful for generating a sequence of values. 4 1 2 5 7 8 6 3 9 this is kind of a generator-counter combo. I've used these for sequencing steps in a more complex process (another FSM!). - that would be the clock. CS447
14
these arrows on the right are unconditional transitions
Controllers let's say you want to make a simple vending machine it accepts nickels and dimes and lets you buy 25¢ items 0¢ 5¢ 10¢ 15¢ 20¢ 25¢ 30¢ nickel dime dispense give nickel - unconditional transitions happen… unconditionally… - basically, when the clock signal happens. these arrows on the right are unconditional transitions CS447
15
Multiplication and Division practical FSMs
CS447
16
Remember this? we used this algorithm to do multiplication:
how might we make a circuit to count the steps? for(n bits in multiplier) { if((multiplier & 1) != 0) product += multiplicand multiplicand <<= 1 multiplier >>= 1 } what do we use to make a decision? what do we use to store values? - an FSM to count the steps and sequence the actions… - a MUX or write enable to make the decision… - registers to store the values… CS447
17
+ 1 A very common pattern D Q have a look at simple_counter.circ
this is a very simple FSM. every clock tick, it adds 1 to the value in the register. this is the hardware equivalent of "x = x + 1". this could really be anything though. like… shifting? CS447
18
So… what are we gonna need
we've got 3 variables (+1 for the loop counter) we're doing 2 shifts and (maybe) an add on each loop D Q + product kindaaa…? D Q << 1 multiplicand how do we decide when to add to the product? D Q >> 1 multiplier D Q + 1 loop step how do we know when to start and stop? - well, gee whiz, this feels like a GREAT topic for a LAB doesn't it CS447
19
Fast multiplication as a circuit
remember there were two phases: calculating the partial products summing them calculating the partial products is easy it's just shifts and ANDs in hardware, shifting can be done by just rerouting wires! summing the partial products is easy we use a binary tree of adders! the product just pops out the end. of course, this uses a lot of silicon… have a look at fast_mult_4x4.circ Fun Stuff Partial Products + CS447
20
subtraction and shifting…
Deja vu We used this division algorithm: divisor <<= n (bits in dividend) remainder = dividend quotient = 0 for(n bits in dividend) { divisor >>= 1 if(divisor > remainder) { append 0 to quotient } else { remainder -= divisor append 1 to quotient } another for loop… another if-else… subtraction and shifting… CS447
21
- >> << + Feels pretty familiar 1 1 1
we've got 3 variables (+1 for the loop counter) we're doing 2 shifts and (maybe) a subtract on each loop D Q - remainder kindaaa…? D Q >> 1 divisor how do we "append a 0 or 1" to the quotient? D Q << 1 quotient D Q + 1 loop step how do we know when to start and stop? - again, labtime - "appending a 0 or 1" is just setting the low bit after shifting left CS447
22
Their similarity is no coincidence
in MIPS, both mul and div use the HI and LO registers this is because in the original design, both algorithms used the same registers, just with different controllers they do some fancy stuff to save bits check out the book – it goes into way too much detail on this, but it's kinda neat your lab will do something similar! hohohoho! CS447
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.