Professional Documents
Culture Documents
Lecture 6
Algorithmic State Machines (ASMs)
ECE 474a/575a 1 of 21
Susan Lysecky
Control
Provides command signals that
coordinate the execution of various
operations in data section to
accomplish desired task
ECE 474a/575a 2 of 21
Susan Lysecky
Lamp doesn’t
Ingredients work int fib(int n)
1/3 cup unsweetened cocoa {
1/4 cup cornstarch if (n < 2)
2 tablespoons butter
2 2/3 cups skim milk No return n;
Lamp plugged Plug in lamp
else
in?
Steps return fib(n-1) + fib(n-2);
Yes }
1. Combine all ingredients in a small saucepan.
2. Heat over low heat, stirring constantly, until Yes
mixture boils. Boil gently, stirring constantly, Bulb burned Replace bulb
for one minute. out?
3. Pour into serving dishes and chill until No
thickened.
Buy new lamp
ECE 474a/575a 3 of 21
Susan Lysecky
1
Flowcharts and Algorithmic State Machines (ASM)
Flowchart
Convenient way to graphically specify sequence of procedural steps and decision
paths for algorithm
Enumerates sequence of operations and conditions necessary for execution
ECE 474a/575a 4 of 21
Susan Lysecky
ASM Chart
ECE 474a/575a 5 of 21
Susan Lysecky
State box
Example
State name: S_pause
Binary encoding: 0101
Register operation: R ← 0 S_pause 0101
ECE 474a/575a 6 of 21
Susan Lysecky
2
Decision Box
Example
Check B
If B is true (=1), take path marked 1
If B is false (=0), take path marked 0
ECE 474a/575a 7 of 21
Susan Lysecky
Conditional Box
Unique to ASM
From exit path of decision box
Example
Status of input B checked B
1 0
Conditional operation executed depending
on result coming from decision box
If B = 1, assert Incr_Reg signal Incr_Reg
ECE 474a/575a 8 of 21
Susan Lysecky
ASM Block
Structure consisting of
Reset_b
One state box S_0 001
Simplifications
ASM Block not usually drawn because
blocks are well defined
Can label just the “1” and omit the “0”
3
Interpretation of Timing Operations
Condition E evaluated
If E= 1
E
clear B 0 1
In ASM the entire block considered as S_1 010 S_2 011 S_3 100
one unit
All operations within block occurring
during single edge transition
The next state evaluated during the
same clock
System enters next state S_1, S_2, or
S_3 during transition of next clock
ECE 474a/575a 10 of 21
Susan Lysecky
ASM Example
Example if(start == 1)
goto S1
Want to detect the number of 1’s in a 2- else
bit register called Input goto S0
S1:
start input indicates when to begin busy = 1;
comparison if(Input[1] == 1)
busy output indicates when comparison in
ones ++;
progress goto S2
ones hold count value S2:
busy = 1;
F outputs result if(Input[0] == 1)
ones ++;
goto S3
S3:
busy = 0;
F = ones;
goto S0
ECE 474a/575a 11 of 21
Susan Lysecky
Input[1] == 1
1 goto S2
S2:
ones++ busy = 1;
if(Input[0] == 1)
ones ++;
S_2 011
busy = 1 goto S3
S_3 111 S3:
busy = 0 busy = 0;
1
Input[0] == 1
F = ones
F = ones;
ones++
goto S0
ECE 474a/575a 12 of 21
Susan Lysecky
4
ASM – Mux
4x1 mux
F = x4 F = x3 F = x2 F = x1
ECE 474a/575a 13 of 21
Susan Lysecky
A B S_0 001
cout FA cin
1
a
F
1 1
b b
a b cin f cout
0 0 0 0 0 1 1 1 1
cin cin cin cin
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
f=1 f=0 f=0 f=1 f=0 f=1 f=1 f=0
1 0 0 1 0
cout = 1 cout = 1 cout = 1 cout = 0 cout = 1 cout = 0 cout = 0 cout = 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
ECE 474a/575a 14 of 21
Susan Lysecky
Smaller Multiplier
a3 a2 a1 a0
b0
pp4 pp3 pp2 pp1
b1
0 0
b2
+ (5-bit)
00 a
b3
+ (6-bit)
000
p7..p0
ECE 474a/575a 15 of 21
Susan Lysecky
5
Smaller Multiplier -- Sequential (Add-and-Shift) Style
ECE 474a/575a 16 of 21
Susan Lysecky
rsload
load
rsclear clear running sum
rsshr shr register (8)
ECE 474a/575a 17 of 21
Susan Lysecky
mrld
load 0011
register (4)
Step 2
mr3 4-bit adder
• Check multiplier bit 1 (mr1)
• mr0=1, add multiplicand to running sum mr2
mr1
• Shift running sum right 1 position mr0
rsload
Step 3 load
rsclear running sum
clear
• Check multiplier bit 2 (mr2) rsshr
• Shift running sum right 1 position
shr 00000000
00010010
00100100
01001000
10010000
00110000
01100000
register (8)
Step 4
• Check multiplier bit 3 (mr3)
• Shift running sum right 1 position
product
ECE 474a/575a 18 of 21
Susan Lysecky
6
ASM – Sequential Multiplier
multiplier multiplicand
Reset_b start
multiplicand
mdld register (4)
load
S_0
start multiplier
controller
1
mr1 mrld register (4)
1 load
rsload = 1 mr3 4-bit adder
S_1 mr2
S_4 mr1
mdld = 1 mr0
rsshr = 1
mrld = 1
rsclear = 1 rsload load
1 rsclear clear running sum
mr2 rsshr shr register (8)
S_2
rsload = 1
S_5
mr0
1 rsshr = 1
rsload = 1 product
1
mr3
S_3
rsload = 1
rsshr = 1
S_6
rsshr = 1
ECE 474a/575a 19 of 21
Susan Lysecky
ASMs to FSMDs
1 B 0
0 E 1
Incr_Reg F Clear_B
0 1
S_1 010 S_2 011 S_3 100
S_0 A=A+1
S_pause A1 E’F’
E / Clear_B = 1
R=0 E’F
B B’ / Incr_Reg = 1
Start_OP = 1
S_1 S_2 S_3
ECE 474a/575a 20 of 21
Susan Lysecky
ECE 474a/575a 21 of 21
Susan Lysecky