Upload
hamza-core
View
215
Download
2
Tags:
Embed Size (px)
Citation preview
Toward a general purpose computer
Example: Game of Life
Game of Life
For Each Line
For Each Cell Solve Cell
Game of Life
For Each Line
For Each Cell Solve Cell
Generation Line CellMatrix
Modularity
Generation Module Matrix Module Line Module Cell Module
Algorithm for the Generation Module
1. CurrentGen = 02. Solve for current Matrix3. CurrentGen++4. If CurrentGen < MAX_GEN
goto 2
Solve Matrix
0. j = 11. Calculate line (j)2. If j < MAX_LINE
2.1 j++2.2 goto 1.
3. STOP
Calculate Line j0. i = 0, tmp = 01. Calculate Cell i.2. If alive, set location i in tmp to alive3. If i < MAX_CELL
3.1 i++3.2 goto 1.
4. Store tmp in : even generation: i+16odd generation : i-16
CellAlive(cell index i, line index j)
0. N = Count_Neighbors(i,j-1,false)1. N = N+Count_Neighbors(i,j,true)2. N =
N+Count_Neighbors(i,j+1,false)3. If N > MIN && N < MAX 3.1 Return alive4. Return dead
Count_Neighbors(index i,line j,
center)
0. N = 0 1. If alive in location [i-1,j]: N=N+12. If not center:
2.1 If alive in location [i,j]: N=N+1
3. If alive in location [i+1,j]: N=N+14. Return N
Algorithm implementation
Algorithm
How to do? What to do?
The operation itself control
The operations in the algorithm:
Operations: Add Subtract
The operation:Defining interfaces
CountNeighbors
CellAlive
Calculate Line
Solve Matrix
Generation
Return Number of Neighbor: N
Alive: 0..010..0
Dead: 0000000
(i-1) location
Return the line
The matrix
Return
The Operation itself
Implementing instructionsModule Count_Neighbors, instruction 1, 2.1, 3
decode(i-1) = 0001000AND
Line (j) = 00010100
Result = 00010000
decode(i-1) = 0001000AND
Line (j) = 00000100
Result = 00000000
Zero – cell in location i is dead
Non Zero – cell in location i is alive
If alive in location [i-1,j]
The Operation itself
Implementing instructionsModule Count_Neighbors, instruction 1, 2.1, 3
Alive if AND(line,decode(i-1)) is not zero
If alive in location [i-1,j]
The Operation itself
The operations in the algorithm:
Operations: Add Subtract The logic AND + Check if zero
The Operation itself
Small ALU (arithmetic logic unit)
Op selector
Meaning Result
00 Add Res = InputA+InputB
01 Subract Res = InputA+ NOT(InputB)+1
10 AND Res = AND(InputA,InputB)
11 Decode Res = decode(InputA)
The Operation itself
Small ALU
MUX
S0S1S2
Adder
Adder
1
ReductionOR
Zero Result
Input A Input B
Decode
StatusBit
The Operation itself
Small ALU
StatusBit
The Operation itself
ALU
isZero
Op
InputBInputA
Implementation of AND(line,decode(i+1))
Reg1
Reg2
Reg3
Regn
Implementation of AND(line,decode(i+1))
Reg1
Reg2
Reg3
Regn
ReadA
ReadB
1
2
Connected like MUX 1
Implementation of AND(line,decode(i+1))
Reg1
Reg2
Reg3
Regn
ReadA
ReadB
1
2
Decoder
Enable Write
Write Address
Write Data
Implementation of AND(line,decode(i+1))
Registers
Data 1
Data 2
Data 1 Address
Data 2 Address
WriteAddress
Write Data
Write
Variables of the algorithmCount_Neighbors
Variable Meaning AddressCurrentLine Hold the current
line0
I The current index 1
N The Neighbor 2
Tmp Temporary space 3
Constant 1 Constant 1 5
ControlVariable A flag to determine if the operation should
be performed
6
Center Is it the center 7
Variables of the algorithmCount_Neighbors
Variable Meaning AddressCurrentLine Hold the current
line0
I The current index 1
N The Neighbor 2
Tmp Temporary space 3
Constant 1 Constant 1 5
ControlVariable A flag to determine if the operation should
be performed
6
Center Is it the center 7
Register/ALU circuit
Registers
Data 1 Address
Data 2 Address
WriteAddress
Write
ALU
Op
Extend 1to 16
MU
X R0R1
ExternalInput
0
1
2
Control Algorithm is zero[AND(line,decode(i+1))]
If alive in location [i+1,j]: N=N+1
Algorithm instruction
Instruction a. Tmp = is zero[AND(Currentline,decode(i+1))]
b. If controlVariable=0000001: N=N+1
The Operation itself
Control Algorithm is zero[AND(line,decode(i-1))]
Tmp = is zero[AND(line,decode(i-1))]Instruction
The Operation itself
t0. Tmp = i-1t1. Tmp = decode(Tmp)t2. controlVariable = is zero[AND(CurrentLine, Tmp)]
Micro-Instruction
Micro instruction implementation
t0. Data 1 Address = 1Data 2 Address = 5WriteAddress = 3
Write = 1 Op = 01R0R1 = 01
Micro-Instruction
The Operation itself
a. Tmp = i+1b. Tmp = decode(Tmp)c. controlVariable = is zero[AND(CurrentLine, Tmp)]
Subtract
i1
tmp
The result of the ALU
Micro instruction implementation
t1. Data 1 Address = 3Data 2 Address = 0WriteAddress = 4
Write = 1 Op = 11R0R1 = 01
The Operation itself
a. Tmp = i+1b. Tmp = decode(Tmp)c. controlVariable = is zero[AND(CurrentLine, Tmp)]
Decode
tmpIrrelevant
tmp
The result of the ALU
Micro-Instruction
Micro instruction implementation
t2. Data 1 Address = 0Data 2 Address = 3WriteAddress = 6
Write = 1 Op = 10R0R1 = 00
The Operation itself
a. Tmp = i+1b. Tmp = decode(Tmp)c. controlVariable = is zero[AND(CurrentLine, Tmp)]
And
Line in register itmpcontrolVariable
The zero status bit
Micro-Instruction
Instruction Hierarchy
Instruction
Micro-Instruction
Micro-Instruction
Micro-Instruction
Micro-Instruction
Instruction
Algorithmic Instruction
The Operation itself
Instruction Hierarchy
Instruction
t0: Micro-Instruction
tn: Micro-Instruction
t0: Micro-Instruction
tn: Micro-Instruction
Instruction
Each micro instruction = 1 cycle
Timing Variable
s
Timing variables (example with 4 time variables)
CP
t0
t1
t2
t3
One instruction
Generating Timing variablesexample with 16 timing variables
CP Register 4bits
Adder
1Decoder
t0
t15
Control of Count_Neighbor
1. N=0
3. i-1 alive?
4. N=N+1
5. Is Center?
6. i alive
7. N=N+1
Yes
No
No
Yes
8. i+1 alive
Yes
No
9. N=N+1
end
Yes
No
Control of Count_Neighbor
0000
0001
0010
0011
0100
0101
0110
0111
1000
1. N=0
3. i-1 alive?
4. N=N+1
5. Is Center?
6. i alive
7. N=N+1
Yes
No
No
Yes
8. i+1 alive
Yes
No
9. N=N+1
end
Yes
No
Control of Count_Neighbor
0000
0001
0010
0011
0100
0101
0110
0111
1000
1. N=0
3. i-1 alive?
4. N=N+1
5. Is Center?
6. i alive
7. N=N+1
Yes
No
No
Yes
8. i+1 alive
Yes
No
9. N=N+1
end
Yes
No
Putting it all together:implementing what to do with ROM
Current State
Timing CV C D1 D2 WA W Op R0R1t0 t1 t2 t3
ROM Input ROM Output
The current state(4 bits) The current timing variable
(1 bits)
Control variable (16bits)
CenterRegister 7 (16bits)
Putting it all together: implementing what to do with ROM
Data 1 Address
ROM Input ROM Output
Data 2 Address Write-Data MUX control
WriteAddress
WriteALU Operation
Current State
Timing CV C D1 D2 WA
W Op R0R1
t0 t1 t2 t3
Putting it all together: implementing what to do with ROMROM Input ROM Output
Current State
Timing CV C D1 D2 WA W Op R0R1
t0 t1 t2 t3
0001 1 0 0 0 1 5 3 1 01 01
0001 0 1 0 0 3 0 4 1 11 01
0001 0 0 1 0 0 3 6 1 10 00
0010 0 0 0 1 0 0 0 0 000 01t0. Tmp = i+1t1. Tmp = decode(Tmp)t2. controlVariable = is
zero[AND(CurrentLine, Tmp)]t3. do nothing
Putting it all together: implementing what to do with ROMROM Input ROM Output
Current State
Timing CV C D1 D2 WA W Op R0R1
t0 t1 t2 t3
0001 1 0 0 0 1 5 3 1 00 01
0001 0 1 0 0 3 0 4 1 11 01
0001 0 0 1 0 0 3 6 1 10 00
0010 0 0 0 1 0 0 0 0 000 01t0. Tmp = i+1t1. Tmp = decode(Tmp)t2. controlVariable = is
zero[AND(CurrentLine, Tmp)]t3. do nothing
Putting it all together: implementing what to do with ROMROM Input ROM Output
Current State
Timing CV C D1 D2 WA W Op R0R1
t0 t1 t2 t3
0001 1 0 0 0 1 5 3 1 00 01
0001 0 1 0 0 3 0 4 1 11 01
0001 0 0 1 0 0 3 6 1 10 00
0010 0 0 0 1 0 0 0 0 000 01t0. Tmp = i+1t1. Tmp = decode(Tmp)t2. controlVariable = is
zero[AND(CurrentLine, Tmp)]t3. do nothing
Putting it all together: implementing what to do with ROMROM Input ROM Output
Current State
Timing CV C D1 D2 WA W Op R0R1
t0 t1 t2 t3
0001 1 0 0 0 1 5 3 1 00 01
0001 0 1 0 0 3 0 4 1 11 01
0001 0 0 1 0 0 3 6 1 10 00
0010 0 0 0 1 0 0 0 0 000 01t0. Tmp = i+1t1. Tmp = decode(Tmp)t2. controlVariable = is
zero[AND(CurrentLine, Tmp)]t3. do nothing
Control of Count_Neighbor
0000
0001
0010
0011
0100
0101
0110
0111
1000
1. N=0
3. i-1 alive?
4. N=N+1
5. Is Center?
6. i alive
7. N=N+1
Yes
No
No
Yes
8. i+1 alive
Yes
No
9. N=N+1
end
Yes
No
t0. Set Current State 0001t1. Set Current State 0001t2. Set Current State 0001t3. If ControlVariable=1
Set Current State 0010t3. If ControlVariable=0
Set Current State 0011
Current State = 0001
Putting it all together:implmenting control with ROM
ROM Input ROM Output
Current State
Timing CV C NextState
t0 t1 t2 t3
0001 1 0 0 0 0001
0001 0 1 0 0 0001
0001 0 0 1 0 0001
0001 0 0 0 1 1 0010
0001 0 0 0 1 0 0011
Here is the branch.
ROM
Timing Variable CurrentState
Registers
ALUExtend 1
to 16
MU
XR0R1
Resultzerobit
Op
D1D2
WA
Write
WriteData
Next State
Current State