Finite State Machines מבוסס על הרצאות של יורם זינגר, האוניברסיטה העברית י"ם יהודה אפק, נתן אינטרטור אוניברסיטת תל אביב
האוטומט פולט 1 אחרי ש " ראה " לפחות ים מאז ה - 0 האחרון. פלט מצוייר במצבים Moore FSM 00/0 01/0 11/0 10/ =I קלט ( כמקודם ) =O פלט Finite State Machine (FSM)
האוטומט פולט 1 אחרי ש " ראה " לפחות ים מאז ה - 0 האחרון. פלט מצוייר על הקשתות Mealy FSM 0/00/0 0/00/0 0/00/0 1/01/0 1/01/0 1/11/1 0/00/0 1/11/1 קלט ( כמקודם ) פלט
טבלת המצבים –Moore AtAt BtBt I=0I=1 A t+1 B t+1 A t+1 B t+1 OtOt הפלט תלוי ב – A & B 00/0 01/0 11/0 10/
טבלת המצבים - Mealy AtAt BtBt X=0X=1 X=0X=1 A t+1 B t+1 A t+1 B t+1 OtOt OtOt הפלט תלוי ב - X
טבלת המצבים – Moore AtAt BtBt I=0I=1 A t+1 B t+1 A t+1 B t+1 OtOt /0 01/0 11/0 10/ A t AB I B t AB
דוגמא - Moore כניסה אחת ויציאה אחת 2FF מסוג Data 4 מצבים. A B D DQ Q’ Q A t+1 = A*I + B * I= I(A+B) I B t+1 = A*I O = A*B O
דוגמא – Mealy כניסה אחת ויציאה אחת היציאה תלויה ב - Q A, Q B ו - X. 2FF מסוג Data 4 מצבים. A B X Out D DQ Q’ Q
Moore Vs. Mealy פלט : Moore – פונקציה של המצב לבד Mealy – פונקציה של המצב והקלט אוטומט : Moore – הפלט " רשום " על המצב Mealy – הפלט " רשום " על הקשת ( מעבר ) שיקולים : Moore – לא תלוי ב " יציבות " הקלט ( מספיק שיהיה קבוע T s + T h ) אך ידרשו FFs נוספים אם דרושה תלות היציאה בקלט. Mealy – פשוט לממוש אם יש תלות של היציאה בקלט אך נדרשת יציבות. Moore שקול ל – Mealy ( ולהפך )
נוהל עיצוב 1. הגדר במילים את פעולת המעגל. 2. בנה את טבלת המצבים ( אוטומט ) 3. צמצם / מצא ייצוג קטן של אוטומט המצבים. 4. קבע משתנים אשר ייצגו את המצבים ( בצורה וקטורית ). קבע את מספר הדלגלגים והתאם אות לכל דלגלג. 5. בחר בסוג הדלגלג להשתמש בו. 6. קבל טבלאות העירור והיציאות של המעגל מטבלת המצבים. 7. חשב את פונקציות היציאה של המעגל ואת פונקציות הכניסה של FF ( בעזרת מפות קרנו או כל שיטה אחרת ) 8. צייר הדיאגרמה הלוגית. *
דוגמת תכנון מזרח מרכזמערב " שמאלה " "ימינה" " שמאלה " " ימינה "" שמאלה " " תקין " " תקוע " I Robot
אוטומט המצבים – תיאור סמלי : מרכז מערבמזרח תקין / שמאל תקין / ימין תקין / שמאל תקין / ימין תקוע / ימין תקוע / שמאל
אוטומט המצבים : " ימין ": 0 " שמאל ": 1 תקין : 0 תקוע : מזרח מערב מרכז 1/0 0/0 1/0 0/0 0/1 1/1 BA קלט פלט 3 מצבים נזדקק ל – 2FF 2FF יכולים " לזכור " 4 מצבים. מצב שלא משתמשים בו (" 11") המצב הנוכחי קלט X המצב הבא פלט Y A BAB
המצב הנוכחי קלט X המצב הבא פלט Y A BAB טבלת המצבים + מעברים :
פונקציות יציאה + מצב הבא : מימוש עבור D-FF 1 1 BtBt XtXt AtAt 11 BtBt XtXt AtAt 1 1 BtBt XtXt AtAt A(t+1) = B’X’ = (B+X)’ B(t+1) = A’X Y(t) = AX’ + BX
דיאגרמה לוגית : A B Q Q’ D C Q D C X B’X’ A’X y BX AX’ מימוש עבור DFF ( שעון מושמט )
How many state bits will we need? Preview: Graphical Specification of FSM
Finite State Machine for Control
Execution Cycle Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Obtain instruction from program storage Determine required actions and instruction size Locate and obtain operand data Compute result value or status Deposit results in storage for later use Determine successor instruction
The control signals decoder We just implement the table of slide 54: Let’s look at ALUSrcA: it is “0” in states 0 and 1 and it is “1” in states 2, 6 and 8. In all other states we don’t care. let’s look at PCWrite: it is “1” in states 0 and 9. In all other states it must be “0”. And so, we’ll fill the table below and build the decoder.
The state machine “next state calc.” logic R-type=000000, lw=100011, sw=101011, beq=000100, bne=000101, lui=001111, j= , jal=000011, addi= Fetch 0 Jump 9 WBR 7 Load 3 Branch 8 ALU 6 AdrCmp 2 Store 5 Decode 1 WB 4 lw+sw R-type beq j swlw IR31IR30IR29IR28IR27IR26 opcode S3S2S1S0 current state S3S2S1S0 next state X0XXXXX X X1 0X XXX XXX X XXXXX R-type lw sw lw+sw
Interrupt and exception Type of event From Where ? MIPS terminology Interrupt External I/O device request Invoke Operation system Internal Exception From user program Arithmetic Overflow Internal Exception Using an undefined Instruction Internal Exception Hardware malfunctions Either Exception or interrupt
Exceptions handling Exception typeException vector address (in hex) Undefined instruction c Arithmetic Overflow c We have 2 ways to handle exceptions: Cause register or Vectored interrupts MIPS – Cause register
Handling exceptions
Fetch Jump WBR Load Branch ALU AdrCmp Store Decode WB lw+sw R-type be q j swsw lw SavePC 10 IRET 1 JumpInt 11 Handling interrupts:
PLA Implementation If I picked a horizontal or vertical line could you explain it?
ROM = "Read Only Memory" –values of memory locations are fixed ahead of time A ROM can be used to implement a truth table –if the address is m-bits, we can address 2 m entries in the ROM. –our outputs are the bits of data that the address points to. m is the "heigth", and n is the "width" ROM Implementation mn
How many inputs are there? 6 bits for opcode, 4 bits for state = 10 address lines (i.e., 2 10 = 1024 different addresses) How many outputs are there? 16 datapath-control outputs, 4 state bits = 20 outputs ROM is 2 10 x 20 = 20K bits (and a rather unusual size) Rather wasteful, since for lots of the entries, the outputs are the same — i.e., opcode is often ignored ROM Implementation
Where are We Going?? מבנה מחשבים Arithmetic Single/multicycle Datapaths IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB PipeliningMemory Systems I/O
Break up the table into two parts — 4 state bits tell you the 16 outputs, 2 4 x 16 bits of ROM — 10 bits tell you the 4 next state bits, 2 10 x 4 bits of ROM — Total: 4.3K bits of ROM PLA is much smaller — can share product terms — only need entries that produce an active output — can take into account don't cares Size is (#inputs #product-terms) + (#outputs #product-terms) For this example = (10x17)+(20x17) = 460 PLA cells PLA cells usually about the size of a ROM cell (slightly bigger) ROM vs PLA
Microprogramming What are the “microinstructions” ?
A specification methodology –appropriate if hundreds of opcodes, modes, cycles, etc. –signals specified symbolically using microinstructions Will two implementations of the same architecture have the same microcode? What would a microassembler do? Microprogramming
Details
Microinstruction format
No encoding: –1 bit for each datapath operation –faster, requires more memory (logic) –used for Vax 780 — an astonishing 400K of memory! Lots of encoding: –send the microinstructions through logic to get control signals –uses less memory, slower Historical context of CISC: –Too much logic to put on a single chip with everything else –Use a ROM (or even RAM) to hold the microcode –It’s easy to add new instructions Maximally vs. Minimally Encoded
Microcode: Trade-offs Distinction between specification and implementation is sometimes blurred Specification Advantages: –Easy to design and write –Design architecture and microcode in parallel Implementation (off-chip ROM) Advantages –Easy to change since values are in memory –Can emulate other architectures –Can make use of internal registers Implementation Disadvantages, SLOWER now that: –Control is implemented on same chip as processor –ROM is no longer faster than RAM –No need to go back and make changes
“Macro and micro - instruction” Interpretation Main Memory execution unit control memory CPU ADD SUB AND DATA User program plus Data this can change! AND microsequence e.g., Fetch Calc Operand Addr Fetch Operand(s) Calculate Save Answer(s) one of these is mapped into one of these
The Big Picture