Digital Systems - Mock Exam 1
Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.
In questa pagina 24
Mock exam built on the model of the exams of the equivalent course taught in Italian (Circuiti Digitali, Engineering, UniPD: the papers of 21 June 2022 and 11 July 2022). It keeps their structure: 20 multiple choice quizzes with three options each (one correct answer) and 3 exercises on separate sheets (Karnaugh maps, finite state machine design, VHDL of a state machine with a test bench). The real papers do not print the points or the duration, so these are a proposal: quizzes for a correct answer, for a wrong one, if left blank (20 points in total); exercises 10 points each; total 50 points, grade points . Proposed duration: 3 hours. No material allowed: no books, notes, calculators or phones.
Because the course in English also covers computer organization and memory, 4 of the 20 quizzes (17 to 20) are on pipelining and cache; the Italian papers have a similar share of questions on the processor and on memory. The first 16 quizzes are centred on number systems, two's complement and overflow, Boolean algebra, universal gates, gate delays, latches and flip-flops.
Quiz 1
Integers from to are stored in binary with the minimum possible number of bits. How many bits are needed?
- a.
- b.
- c.
Show the result
b.
Show the full solution
There are different values, and bits distinguish values. is too small, is enough, so bits (the largest number, , is ). Answer a. is too small ( bits give only values); answer c. confuses the number of values with the number of bits. Typical mistake: the number of bits depends on how many values must be distinguished, not on how many decimal digits are written. Theory: Number Systems and Base ConversionsA number in base r is the sum of a_i r^i with digits from 0 to r-1. Conversions: base r to decimal by weighted sum; decimal to base r by successive divisions (integer part, remainders read bottom-up) and successive multiplications (fractional part, integer parts read top-down); binary to octal or hexadecimal by groups of 3 or 4 bits starting from the radix point. Binary sum, difference and product follow the decimal rules with borrows and shifted partial products.Number Systems and Base Conversions →, Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels →.
Quiz 2
The binary number (10 bits) written in hexadecimal is:
- a.
- b.
- c.
Show the result
a.
Show the full solution
Each hexadecimal digit is exactly bits, and the groups are formed starting from the right (the least significant bit), padding with zeros on the left: . Then , (13), : . Grouping from the left (, completed with zeros on the right) gives , the second typical mistake. Answer c., , is the decimal value of the number (), not its hexadecimal form. Theory: Number Systems and Base ConversionsA number in base r is the sum of a_i r^i with digits from 0 to r-1. Conversions: base r to decimal by weighted sum; decimal to base r by successive divisions (integer part, remainders read bottom-up) and successive multiplications (fractional part, integer parts read top-down); binary to octal or hexadecimal by groups of 3 or 4 bits starting from the radix point. Binary sum, difference and product follow the decimal rules with borrows and shifted partial products.Number Systems and Base Conversions →.
Quiz 3
The number represented in two's complement on bits is:
- a.
- b.
- c.
Show the result
c.
Show the full solution
. The two's complement is the one's complement plus : invert every bit, , then add : . Check: (the most significant bit has weight ). Answer b. stops at the one's complement (forgot the ); answer a. is the sign-magnitude representation ( followed by ). Theory: Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →.
Quiz 4
The range of the integers that can be represented in two's complement with bits is:
- a. from to
- b. from to
- c. from to
Show the result
b.
Show the full solution
With bits in two's complement the range is to ; for it is to . The range is asymmetric because there is only one zero and the pattern is , whose opposite does not fit. Range a. belongs to sign-magnitude (two zeros, symmetric range); c. would need bits. Theory: Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →.
Quiz 5
The numbers and are added on bits in two's complement. The result is and:
- a. overflow has occurred: two positive numbers gave a result that looks negative
- b. there is no overflow and the result is
- c. there is no overflow and the result is
Show the result
a.
Show the full solution
and are both positive, but the sum exceeds the maximum : the sum bits have the sign bit at (they would read ), so the result is wrong. Rule: overflow happens when the two addends have the same sign and the result has the opposite one; in terms of carries, the carry into the sign bit ( here) differs from the carry out of it (). Answer b. trusts the bits; c. reads the bits as unsigned, but the numbers are signed on bits and is not representable. Typical mistake: using the carry out alone as the overflow flag for signed numbers. Theory: Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →.
Quiz 6
The complement of the function is:
- a.
- b.
- c.
Show the result
b.
Show the full solution
De Morgan: negate every literal and swap sums and products. . Quick check with : , so must be ; option b. gives (correct), option a. gives (wrong, the second factor was not complemented correctly). Option c. is what one gets by negating the literals without swapping AND and OR. Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →.
Quiz 7
The expression is equivalent to:
- a.
- b.
- c.
Show the result
a.
Show the full solution
Use (a theorem of Boolean algebra): . Then is absorbed by (), so the whole expression is . Check with : the original is , and would give (option c. is wrong); with the original is and would give (option b. is wrong). Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →.
Quiz 8
The minimum number of 2-input NOR gates needed to build a 2-input AND gate (an inverter is a NOR with the two inputs tied together) is:
- a.
- b.
- c.
Show the result
c.
Show the full solution
By De Morgan : two NORs with tied inputs make and , and a third NOR combines them. Total gates. Dually the OR needs NOR gates and the AND with NAND gates needs ; the AND with NOR gates is the expensive case. Theory: Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →.
Quiz 9
Which of the following sets of gates is not universal (that is, cannot build every Boolean function)?
- a.
- b.
- c.
Show the result
b.
Show the full solution
NAND alone and NOR alone are universal: each can make the inverter (tie the inputs) and hence AND and OR. With only AND and OR no inversion is possible: every function built from them is monotone (raising an input from to can never lower the output), whereas is not. Without the NOT the set cannot be complete. Theory: Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →.
Quiz 10
An AND gate has a propagation delay of ns. Input is between ns and ns and otherwise; input is between ns and ns and otherwise. The output is between:
- a. ns and ns
- b. ns and ns
- c. ns and ns
Show the result
c.
Show the full solution
The ideal output is when both inputs are , that is from to ns. A real gate reproduces the same waveform shifted by ns on both edges: it rises at ns and falls at ns. Answer a. is the ideal output; b. delays only the rising edge. Typical mistake: forgetting that the delay applies to every transition. Theory: Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →.
Quiz 11
A combinational circuit has the gates ( ns), ( ns), ( ns), ( ns). feeds , feeds , and feeds ; the output is the output of and all the inputs change at the same time. After how long is the output certainly stable?
- a. ns
- b. ns
- c. ns
Show the result
a.
Show the full solution
The delay of the circuit is that of the slowest path (critical path). Path : ns. Path : ns. The output is stable after ns. Answer b. adds up all the gates, as if they were all in series; c. is the shorter path, which would be correct only if the other did not exist. Theory: Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →, Timing of Sequential Systems - Setup, Hold and Maximum Clock FrequencyA flip-flop stores the right value only if its input is stable for the setup time before and the hold time after the clock edge, and its output changes after the propagation delay. In a synchronous circuit the clock period must satisfy T >= t_pd,FF + t_COMB + t_s,FF + t_slack, which fixes the maximum frequency; slowing the clock cures setup violations but not hold violations, which require t_pd,FF,min + t_COMB,min >= t_h. Clock skew modifies both constraints.Timing of Sequential Systems - Setup, Hold and Maximum Clock Frequency →.
Quiz 12
A latch built with two NOR gates (an SR latch, active high inputs) is in an unknown state. The inputs are applied in this order: , , , . The final value of is:
- a. undefined
- b.
- c.
Show the result
c.
Show the full solution
is reset: . is hold: . is set: . The last is hold again: . Since the first input already brings the latch to a known state, it does not matter that the initial state was unknown. The result would be undefined (a.) only if had been applied before returning to . Theory: Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →.
Quiz 13
Which statement correctly compares a D latch (control input ) with a positive-edge-triggered D flip-flop?
- a. both are transparent while the clock is
- b. the latch is transparent while (its output follows ), the flip-flop copies only at the rising clock edge
- c. the flip-flop follows while the clock is , the latch only at the clock edge
Show the result
b.
Show the full solution
A latch is level sensitive: for it is transparent and follows every change of (after the gate delay); for it holds. A flip-flop is not transparent: it is built with two latches in cascade (master and slave) enabled at opposite levels, and the new value of reaches only at the active edge, . Answer a. is false for the flip-flop, answer c. mixes up the two behaviours. Theory: Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →.
Quiz 14
A clock has period ns and is high in ns, ns and so on (it rises at ns). The input is only between ns and ns, and at all other times. All the outputs are initially and the gates are ideal. The output of a positive-edge-triggered D flip-flop and that of a D latch transparent when the clock is are:
- a. flip-flop: always ; latch: between ns and ns
- b. flip-flop: from ns; latch: always
- c. both always
Show the result
a.
Show the full solution
The flip-flop looks at only at the rising edges ( ns, ns, ...): at both instants , so stays (the pulse of between and ns falls between two edges and is ignored). The latch is transparent during ns: from to ns it copies , then follows back to at ns; in it holds . So the latch shows a ns pulse that the flip-flop never sees. This is exactly the reason why synchronous circuits use flip-flops. Theory: Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →.
Quiz 15
In an SR latch built with NOR gates the inputs and are applied. What happens?
- a. the latch is set: and
- b. both outputs go to , which violates , and when the inputs return to the final state cannot be predicted
- c. the latch holds its previous value
Show the result
b.
Show the full solution
With each NOR has an input at , so both outputs become : , which is not a valid pair of complementary values. Moreover, going back to the two gates compete and the final state depends on which input falls first and on the gate delays. For this reason is forbidden; the D latch removes the problem by imposing , . Theory: Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →.
Quiz 16
The decimal number written in BCD is:
- a.
- b.
- c.
Show the result
c.
Show the full solution
BCD writes every decimal digit with its own bits: , , , hence . Answer a., , is the binary value of (): BCD is not the binary form of the number. Answer b. is the BCD of . Theory: Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →.
Quiz 17
A pipelined processor has stages (IF, DOF, EX, WB) and executes instructions with no hazards, one instruction entering the pipeline per clock cycle. The number of clock cycles needed to complete all of them is:
- a.
- b.
- c.
Show the result
a.
Show the full solution
With stages and instructions the cycles are : the first instruction needs cycles, then one more instruction completes every cycle, so . Answer b. forgets the filling of the pipeline; answer c. is the count of a processor that executes one instruction at a time in cycles each (no overlap). Theory: Pipelining and HazardsA pipeline splits execution into stages separated by registers (IF, DOF, EX, WB) working in parallel on different instructions; latency stays the same while throughput grows by less than the number of stages (flip-flop delays, slowest stage). With k stages and N instructions k+N-1 cycles are needed. Hazards stall the pipeline: data hazards (operand not yet written; fixes are NOPs, stalls and forwarding) and control hazards (branches; fixes are NOPs or branch prediction with bubbles).Pipelining and Hazards →.
Quiz 18
In a -stage pipeline (IF, DOF, EX, WB) the register is written in the first half of the WB cycle and the operands are read in the second half of the DOF cycle. There is no forwarding. The two consecutive instructions are
If the hardware solves the data hazard with a stall, instruction 2 is delayed by:
- a. cycles
- b. cycles
- c. cycle
Show the result
c.
Show the full solution
Instruction 1 does IF, DOF, EX, WB in cycles ; instruction 2 would do its DOF at cycle , but is written only at cycle (first half): at cycle it would read the old value, so there is a data hazard. Delaying the DOF by one cycle (DOF at cycle , second half) is enough to read the new value: the stall costs one cycle (one bubble). With forwarding from the EX output no cycle would be lost (a.). Two cycles (b.) would be right only if were written in the second half of WB, so that the read could happen only at cycle . Theory: Pipelining and HazardsA pipeline splits execution into stages separated by registers (IF, DOF, EX, WB) working in parallel on different instructions; latency stays the same while throughput grows by less than the number of stages (flip-flop delays, slowest stage). With k stages and N instructions k+N-1 cycles are needed. Hazards stall the pipeline: data hazards (operand not yet written; fixes are NOPs, stalls and forwarding) and control hazards (branches; fixes are NOPs or branch prediction with bubbles).Pipelining and Hazards →.
Quiz 19
A direct-mapped cache has lines, one word per line. The main memory is addressed with -bit word addresses. How many bits does the tag have?
- a.
- b.
- c.
Show the result
c.
Show the full solution
In a direct-mapped cache the low-order bits of the address select the line (the index) and the high-order bits are the tag, stored with the data and compared at every access. lines need a -bit index, so the tag has bits. Answer a. is the width of the index; b. (the whole address) is the tag of a fully associative cache. Theory: Memory Hierarchy and Cache MemoryMemories form a hierarchy (small fast SRAM, larger slower DRAM, huge slow disks) which works because programs reuse data close in time and in space (locality). A cache hit or miss gives an average access time t_hit plus miss rate times miss penalty; placement can be direct mapped (index = low address bits, tag = high bits), fully associative (tag = whole address, compared in parallel by an associative memory) or k-way set associative (a block can sit in k locations of one set).Memory Hierarchy and Cache Memory →.
Quiz 20
A cache has a hit time of ns, a miss rate of and a miss penalty of ns. The average access time is:
- a. ns
- b. ns
- c. ns
Show the result
a.
Show the full solution
ns. Answer b. is only the contribution of the misses (the hit time is always paid); c. is the access time of a miss (), which happens only of the time. Theory: Memory Hierarchy and Cache MemoryMemories form a hierarchy (small fast SRAM, larger slower DRAM, huge slow disks) which works because programs reuse data close in time and in space (locality). A cache hit or miss gives an average access time t_hit plus miss rate times miss penalty; placement can be direct mapped (index = low address bits, tag = high bits), fully associative (tag = whole address, compared in parallel by an associative memory) or k-way set associative (a block can sit in k locations of one set).Memory Hierarchy and Cache Memory →.
Exercise 1 (points 10)
A control circuit receives a number from to , written in binary on four bits ( is the most significant bit). The values and never occur at the input. The output is if is a prime number () and otherwise (the numbers and are not prime). a) Write the truth table and draw the Karnaugh map, marking the don't care conditions. b) Find the minimum sum of products (SOP) of . c) Draw the circuit using only NAND gates (an inverter is a NAND with the inputs tied together) and count the gates and the gate inputs. d) Every NAND gate, inverters included, has a propagation delay of ns. What is the maximum delay between a change at the inputs and the stabilisation of the output? e) What does the circuit give for and ? Is it a problem?
Show the result
a) for ; for ; don't care (X) for . b) (three products, literals; the minimum is unique). c) : two 2-input NANDs, two 3-input NANDs ( inputs) and two inverters made of NANDs ( and ): NAND gates in total ( gate inputs counting each tied NAND as a 2-input gate). d) ns (path or inverter 3-input NAND 3-input NAND); the other paths take ns. e) and : no problem, those inputs never occur (don't care).
Show the full solution
Part a: truth table and map. The inputs are the bits of , so the minterm of is the row of its binary code (Canonical Forms - Minterms, Maxterms, SOP and POSA minterm is a product containing every variable exactly once and is 1 on a single truth-table row; a maxterm is the dual sum and is 0 on a single row; with n variables there are 2^n of each and the complement of minterm i is maxterm i. Canonical SOP = sum of minterms of rows with F=1; canonical POS = product of maxterms of rows with F=0. They come mechanically from the truth table but are redundant, so they are the starting point for minimization. SOP and POS are two-level circuits.Canonical Forms - Minterms, Maxterms, SOP and POS →):
| 0 | 0000 | 0 | 8 | 1000 | 0 | |
| 1 | 0001 | 0 | 9 | 1001 | 0 | |
| 2 | 0010 | 1 | 10 | 1010 | 0 | |
| 3 | 0011 | 1 | 11 | 1011 | 1 | |
| 4 | 0100 | 0 | 12 | 1100 | 0 | |
| 5 | 0101 | 1 | 13 | 1101 | 1 | |
| 6 | 0110 | 0 | 14 | 1110 | X | |
| 7 | 0111 | 1 | 15 | 1111 | X |
Map with the rows and the columns in Gray code order (), so that adjacent cells differ by one bit; in brackets the value of (Karnaugh Maps and Two-Level MinimizationA Karnaugh map is the truth table arranged in a grid with rows and columns in Gray code, so that adjacent cells (also across opposite edges) differ in one variable. Groups of 2^k ones eliminate k variables and give a product. A prime implicant is a maximal group, an essential one is the only cover of some minterm; the minimum cover has all essentials plus few other primes. For POS, group the zeros. Don't cares may be used as 1 or 0. XOR functions have a checkerboard map and do not simplify.Karnaugh Maps and Two-Level Minimization →):
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 0 (N=0) | 0 (1) | 1 (3) | 1 (2) |
| 01 | 0 (4) | 1 (5) | 1 (7) | 0 (6) |
| 11 | 0 (12) | 1 (13) | X (15) | X (14) |
| 10 | 0 (8) | 0 (9) | 1 (11) | 0 (10) |
Part b: minimum SOP. Group the s in rectangles of adjacent cells, as large as possible; the X cells may be used as when they enlarge a group (never a group made only of X).
- Column (cells ; the is an X): , fixed, and vary: . It covers .
- Block of rows and columns (cells ; again the X in ): and fixed: . It covers (and ).
- The cell () is covered only by the pair : row , columns and : fixed: . It cannot be enlarged: the cells that would complete a rectangle of four, and , are .
All three groups are essential (the cell only by the third, only by , only by ), and together they cover all the s, so the minimum is unique: Check on all the values from to : the expression is exactly for (: third product; : ; : ; : both and ) and for the others (for example : , , because ).
Part c: NAND-only circuit (Combinational Design - Hierarchy and NAND-NOR MappingA combinational circuit has outputs depending only on the present inputs (no memory, no feedback); a sequential one also depends on history (state, memory, feedback). Design flow: specification, truth table, minimum-cost function, logic diagram, verification. With many inputs the hierarchical approach splits the system into reusable blocks (regularity). Basic blocks: one-variable functions, vectors, enabling. Technology mapping in CMOS: SOP to NAND-NAND, POS to NOR-NOR.Combinational Design - Hierarchy and NAND-NOR Mapping →). A SOP is turned into a NAND-NAND network by double negation and De Morgan: . There is one NAND for each product and a final NAND with as many inputs as products:
- and , 2 inputs each;
- and (inverters made of NANDs, Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →);
- , 3 inputs;
- , 3 inputs.
Count: gates with inputs, plus the inverters: gates, inputs if each tied NAND is counted as a 2-input gate ( if an inverter is counted as a one-input gate). The variables and appear only in direct form and need no inverter.
Part d: delay. Every gate has ns, so the delay of a path is ns times the number of gates crossed. Path from or : or or , then the output NAND: gates, ns. Path from or : inverter, , output NAND: gates, ns. The output is certainly stable after the slowest path, ns. (Typical mistake: forgetting that the inverters add a level in the paths of and .)
Part e. For : (), , (): . For : , so . These values are not required (they are "don't care") because and never occur: using the X as in the cell is exactly what allowed the bigger groups and ; the X in was left as .
Typical mistakes: grouping the X cells alone; not using the X cell and so leaving smaller groups (for example instead of ); forgetting the inverters in the NAND count; counting the delay on a wrong path.
Exercise 2 (points 10)
Design a synchronous sequential circuit with a one-bit input (a new bit at every clock cycle) and an output , following the Mealy model, that recognises the sequence in the bits received. during the clock cycle in which the last bit of the sequence is present at the input, that is when the last four bits received, the current one included, are ; otherwise. Overlapping sequences are allowed (with the input the output is twice). The circuit starts in the state of "no useful bit received" and uses positive-edge-triggered D flip-flops. a) Draw the state diagram with the minimum number of states (describe in words what each state means) and write the state table (next state and output). b) How many flip-flops are needed? Use the encoding , , , for and write the table of the next state and of the output. c) Derive with Karnaugh maps the minimum equations of , and . d) For the input (one bit per cycle, starting from ) give for every cycle the present state, the output and the next state. e) Add a synchronous reset (active high) that brings the circuit to : how do the equations of the flip-flops change?
Show the result
a) Four states, all distinguishable. : no useful prefix; : the bits end with ; : they end with ; : they end with . Next state / for and : : , ; : , ; : , ; : , . only in with . b) flip-flops (no unused code). c) ; ; . d) Present states ; (so in cycles , , ); next states . e) and : an AND with on each input; does not change.
Show the full solution
Part a: state diagram. Procedure of Finite State Machines - SynthesisSynthesis of a synchronous sequential circuit follows specifications, state diagram, state table (merging equivalent states), binary state encoding, choice of D flip-flop, flip-flop input and output equations, minimisation, circuit and verification. A state summarises the useful part of history; a sequence recogniser has one state per recognised prefix, reusing states for overlaps. A reset gives a known initial state. Gray encoding (minimum flip-flops) versus one-hot (one flip-flop per state, simpler logic): for the 1101 recogniser Gray costs about half.Finite State Machines - Synthesis →: one state for every prefix of already received, and for every wrong input the state that corresponds to the longest tail of the received bits that is still a prefix of (this rule gives the overlaps).
- : no tail of the received bits is a prefix of (the start, or after a that does not continue a prefix).
- : the bits end with (prefix of length ).
- : the bits end with (prefix of length ).
- : the bits end with (prefix of length ).
Transitions:
- , : the starts a prefix, go to ; : a is not a prefix, stay in .
- , : ends with , still a prefix of length : stay in ; : , go to .
- , : : of its tails (, , ) only is a prefix of , go to ; : , go to .
- , : sequence completed, so ; the last can start a new sequence (overlap) and the next state is ; : has no tail that is a prefix, go to .
State table (next state / ; in a Mealy machine the output is written on the transition):
| present state | ||
|---|---|---|
The diagram is redrawn with four circles and eight arrows labelled : , (loop), (loop), , , , , .
No equivalent states. Two states are equivalent if no input sequence can tell them apart by the outputs. is the only state that gives at once (with ), so it differs from all the others. is told from and by the input : from it gives at the second bit, from and it does not. and are told apart by : from it goes and gives , from it does not. So states are the minimum. (A Moore machine would need one more state, because the output would have to be stored in the state, one cycle later.)
Part b: encoding. gives flip-flops, , and all four codes are used (there are no don't care combinations). The encoding is a Gray sequence along the main path . For a D flip-flop the next state bits are directly the inputs:
| (state) | (next state) | ||
|---|---|---|---|
| 00 () | 0 | 01 | 0 |
| 00 | 1 | 00 | 0 |
| 01 () | 0 | 01 | 0 |
| 01 | 1 | 11 | 0 |
| 11 () | 0 | 01 | 0 |
| 11 | 1 | 10 | 0 |
| 10 () | 0 | 01 | 1 |
| 10 | 1 | 00 | 0 |
:
| 0 | 1 | |
|---|---|---|
| 00 | 0 | 0 |
| 01 | 0 | 1 |
| 11 | 0 | 1 |
| 10 | 0 | 0 |
only in the two cells with and : .
:
| 0 | 1 | |
|---|---|---|
| 00 | 1 | 0 |
| 01 | 1 | 1 |
| 11 | 1 | 0 |
| 10 | 1 | 0 |
The whole column (four cells): . The cell is joined with the cell : the pair with , : . So .
: it is only in the cell , whose neighbours are all and which cannot be enlarged: . Since depends on as well as on the state, the machine is Mealy and changes as soon as changes, within the cycle.
Part d: trace. At every cycle the present state and give (during the cycle) and the next state, which becomes the present state at the following clock edge:
| cycle | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | |
| present state | ||||||||||||||
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | |
| next state |
in cycles , and : the bits are at cycles to , then to (the last of the first sequence is also the first of the second: overlap) and to .
Part e: synchronous reset. A synchronous reset acts only at a clock edge and forces the state to : it is realised with an AND with in front of each input. and . The output is unchanged (it depends only on the present state and on ). With both become and at the next edge the circuit is in whatever the previous state was.
Typical mistakes: building a Moore machine (the output would come one cycle late and one more state is needed); returning to instead of after the complete sequence (this loses the overlap); going from with to instead of (the last is a prefix); reading in the next state instead of the present state and the current input.
Exercise 3 (points 10)
Describe in VHDL, in behavioral style, the sequence recogniser of Exercise 2: input , clock and synchronous reset (active high), output (all std_logic). The states are and the machine is a Mealy machine with the following table (next state / ):
| present state | ||
|---|---|---|
The code must separate the memory element (state register) from the purely combinational parts.
- Write
entityandarchitectureof the machine. - Write a test bench (empty entity, clock of period ns starting at
'0', inputs changing on the falling edge of the clock) that applies, one value per clock cycle: cycle :rst='1',x='0'; then, withrst='0', the bits (one per cycle). - Give the state after each rising clock edge and the times at which . Does the test sequence go through all the transitions of the table?
Show the result
- Three processes: state register (clock edge, synchronous reset tested inside the edge branch,
state <= next_state), next state (case state, sensitive tostateandx), output (zequal to'1'only inS3withx='0', sensitive tostateandx). - Test bench with clock process, input process (reset in cycle , then the bits in a loop with
wait for PERIOD) andstd.env.stop. - State after the rising edges: (reset at ns), then, after the bits, . for ns from ns (bit ) and from ns (bit ). Yes: all the pairs (state, input) are visited.
Show the full solution
Part 1: the machine (VHDL - Finite State Machines and Sequential TestbenchesA finite state machine is described in behavioral VHDL with an enumerated type for the states and three processes: the state register (reset and state <= next_state on the clock edge), the next state as a combinational function of state and input (case state, with default next_state <= state), and the output as a combinational function of the state alone (Moore) or of state and input (Mealy). The testbench has a clock process and an input process (initial reset, then a test sequence that visits all states).VHDL - Finite State Machines and Sequential Testbenches →). Three processes work in parallel: the state register (the only one with memory), the next state logic and the output logic. The register process is sensitive to clk only, because the reset is synchronous: it is tested inside the branch of the rising edge and has priority over next_state (VHDL - Latches, Flip-Flops and ResetsIn VHDL a memory element is a process in which some branch does not assign the signal: the D latch is process(D,C) with if C='1' then Q<=D, the positive-edge-triggered flip-flop is process(CLK) with if CLK'event and CLK='1'. Asynchronous reset: RST is in the sensitivity list and tested first (if RST='1' ... elsif clock edge); synchronous reset: only CLK in the list and RST tested inside the clock-edge branch, so a clock edge is needed for it to act. The testbench of a synchronous circuit has a process generating the clock and one applying inputs away from the active edge.VHDL - Latches, Flip-Flops and Resets →). The two combinational processes have all the inputs in the sensitivity list (state and x) and assign their outputs in every branch, so that no latch is inferred (VHDL - Concurrent Statements, Processes and TestbenchesConcurrent VHDL statements are the plain signal assignment, when-else (priority logic, conditions evaluated in order) and with-select (parallel logic, every case covered once, others required). A process is a concurrent statement with a sequential body (if, case, loop) that wakes up when a signal in its sensitivity list changes; for combinational logic the list holds all inputs; signals are updated when the process suspends and the last assignment wins. An if without else or an uncovered case creates unwanted memory. A testbench has an empty entity, the instantiated DUT and a stimulus process with wait statements.VHDL - Concurrent Statements, Processes and Testbenches →). The output is of Mealy type: it depends on state and on x.
library IEEE;
use IEEE.std_logic_1164.all;
entity rec0110 is
port ( clk, rst, x : in std_logic;
z : out std_logic );
end rec0110;
architecture beh of rec0110 is
type state_type is (S0, S1, S2, S3);
signal state, next_state : state_type := S0; -- initial value only for the simulation
begin
-- process 1: state register, synchronous reset
state_register : process (clk)
begin
if clk'event and clk = '1' then
if rst = '1' then
state <= S0;
else
state <= next_state;
end if;
end if;
end process;
-- process 2: next state = f(state, x)
next_state_comb : process (state, x)
begin
case state is
when S0 =>
if x = '0' then next_state <= S1; else next_state <= S0; end if;
when S1 =>
if x = '0' then next_state <= S1; else next_state <= S2; end if;
when S2 =>
if x = '0' then next_state <= S1; else next_state <= S3; end if;
when S3 =>
if x = '0' then next_state <= S1; else next_state <= S0; end if;
end case;
end process;
-- process 3: output = f(state, x) (Mealy)
output_comb : process (state, x)
begin
case state is
when S3 =>
if x = '0' then z <= '1'; else z <= '0'; end if;
when others =>
z <= '0';
end case;
end process;
end beh;Remarks: the three processes copy the table row by row. The case on an enumerated type must cover all the values: all four states are listed in the second process, when others in the third. z is assigned in every branch, so the output logic is purely combinational. If the sensitivity list of the output process contained only state, the output would be of Moore type and would not see x.
Part 2: test bench. An empty entity, a process for the clock and a process for the inputs which changes them on the falling edge, away from the rising edge where the circuit samples (VHDL - Finite State Machines and Sequential TestbenchesA finite state machine is described in behavioral VHDL with an enumerated type for the states and three processes: the state register (reset and state <= next_state on the clock edge), the next state as a combinational function of state and input (case state, with default next_state <= state), and the output as a combinational function of the state alone (Moore) or of state and input (Mealy). The testbench has a clock process and an input process (initial reset, then a test sequence that visits all states).VHDL - Finite State Machines and Sequential Testbenches →):
library IEEE;
use IEEE.std_logic_1164.all;
entity tb_rec0110 is
end tb_rec0110;
architecture test of tb_rec0110 is
signal clk, rst, x, z : std_logic := '0';
constant PERIOD : time := 10 ns;
constant x_seq : std_logic_vector(0 to 14) := "101110010110110";
begin
DUT : entity work.rec0110(beh)
port map (clk => clk, rst => rst, x => x, z => z);
generate_clock : process
begin
clk <= '0'; wait for PERIOD/2; -- rising edges at 5, 15, 25, ... ns
clk <= '1'; wait for PERIOD/2;
end process;
apply_inputs : process
begin
rst <= '1'; x <= '0'; -- cycle 1: reset (the edge at 5 ns sees rst = 1)
wait for PERIOD;
rst <= '0'; -- from 10 ns (falling edge) the reset is released
for i in 0 to 14 loop
x <= x_seq(i); -- bit i applied at 10 + 10 i ns
wait for PERIOD;
end loop;
std.env.stop; -- end of the simulation (at 160 ns)
end process;
end test;The reset must be applied for at least one rising edge, because it is synchronous: here the edge at ns sees rst='1' and brings the state to (the declaration also gives the initial value ). The bit number is applied at the falling edge ns and sampled at the rising edge ns.
Part 3: what the simulation shows. Applying the table to the sequence (state before the edge, input, z during the cycle, state after the edge):
| bit | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x |
1 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
| state before the edge | |||||||||||||||
z |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| state after the edge |
So the states after the rising edges at ns, ns, ... are (reset), then . The output is for the bits (the bits to are ) and (the bits to are , overlapping with the previous one on the common ). Since the machine is Mealy, z rises as soon as x changes (at the falling edge, ns and ns) and falls at the next rising edge ( ns and ns), when the state leaves : it is for ns, and a circuit that uses it samples it at that same rising edge, just before it falls.
The pairs (state, input) visited are , , , , , , , : all , so every row of the table is exercised and both detections (with overlap) appear. The sequence is therefore a complete test for this machine.
Typical mistakes: a reset in the sensitivity list or outside the edge branch (that is an asynchronous reset, not the one required); a process of the output depending only on state (Moore instead of Mealy); a missing branch of the case or an output not assigned in every branch (latch); inputs changing on the rising edge (race between clock and data); a test bench without the initial reset or without std.env.stop.
Self-assessment grid
| exercise | points | what must be there for full marks | typical mistakes |
|---|---|---|---|
| Quizzes 1-16 | 16 | one answer per question; each wrong one costs , so leave blank only if really uncertain | hexadecimal grouped from the left, no in two's complement, carry out used as overflow flag, De Morgan without swapping AND and OR, delay not applied on both edges, sum of all gate delays instead of the critical path |
| Quizzes 17-20 | 4 | cycles, one stall cycle for adjacent dependent instructions, tag address bits index bits, average access time with the hit time included | pipeline filling forgotten, tag and index swapped, miss penalty without the hit time |
| Ex. 1, part a | 2 | truth table and map with the X in | X used wrongly, wrong Gray order of the columns |
| Ex. 1, part b | 4 | with the three groups drawn on the map | groups made only of X, group missing, non-minimal cover |
| Ex. 1, parts c and d | 3 | NAND-NAND network with gates (inverters from tied NANDs), inputs, ns | inverters forgotten, delay computed on the wrong path |
| Ex. 1, part e | 1 | , , explained as don't care | none |
| Ex. 2, parts a and b | 4 | four states with meaning, table with overlaps, flip-flops, encoding table | Moore instead of Mealy, no overlap, with to |
| Ex. 2, part c | 3 | , , | non-maximal groups, without |
| Ex. 2, parts d and e | 3 | trace with in cycles ; on the inputs | read in the next state, reset on |
| Ex. 3, part 1 | 4 | three processes, synchronous reset inside the edge branch, complete case, Mealy output |
asynchronous reset, latch from incomplete branches, Moore output |
| Ex. 3, part 2 | 3 | empty entity, clock, inputs on the falling edge, initial reset, the bits, std.env.stop |
inputs on the rising edge, no reset, no end |
| Ex. 3, part 3 | 3 | states after each edge, at bits and , all pairs covered | counting the Mealy output one cycle late |