Salta al contenuto
Note per Studenti Digital Systems - Mock Exam 1 Report

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 +1+1 for a correct answer, −0.3-0.3 for a wrong one, 00 if left blank (20 points in total); exercises 10 points each; total 50 points, grade == points ×30/50\times 30/50. 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 00 to 999999 are stored in binary with the minimum possible number of bits. How many bits are needed?

  • a. 99
  • b. 1010
  • c. 10001000
Show the result

b.

Show the full solution

There are 10001000 different values, and nn bits distinguish 2n2^n values. 29=512<10002^9=512<1000 is too small, 210=1024≥10002^{10}=1024\ge1000 is enough, so 1010 bits (the largest number, 999999, is 111110011121111100111_2). Answer a. is too small (99 bits give only 512512 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 10110111011011011101 (10 bits) written in hexadecimal is:

  • a. 2DD2DD
  • b. B74B74
  • c. 733733
Show the result

a.

Show the full solution

Each hexadecimal digit is exactly 44 bits, and the groups are formed starting from the right (the least significant bit), padding with zeros on the left: 0010 1101 11010010\ 1101\ 1101. Then 0010=20010=2, 1101=D1101=D (13), 1101=D1101=D: 2DD2DD. Grouping from the left (1011 0111 011011\ 0111\ 01, completed with zeros on the right) gives B74B74, the second typical mistake. Answer c., 733733, is the decimal value of the number (2⋅256+13⋅16+13=7332\cdot256+13\cdot16+13=733), 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 −45-45 represented in two's complement on 88 bits is:

  • a. 1010110110101101
  • b. 1101001011010010
  • c. 1101001111010011
Show the result

c.

Show the full solution

45=00101101245=00101101_2. The two's complement is the one's complement plus 11: invert every bit, 1101001011010010, then add 11: 1101001111010011. Check: −128+64+16+2+1=−45-128+64+16+2+1=-45 (the most significant bit has weight −27-2^{7}). Answer b. stops at the one's complement (forgot the +1+1); answer a. is the sign-magnitude representation (11 followed by 01011010101101). 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 66 bits is:

  • a. from −31-31 to +31+31
  • b. from −32-32 to +31+31
  • c. from −32-32 to +32+32
Show the result

b.

Show the full solution

Quiz 5

The numbers 0110100101101001 and 0100110001001100 are added on 88 bits in two's complement. The result is 1011010110110101 and:

  • a. overflow has occurred: two positive numbers gave a result that looks negative
  • b. there is no overflow and the result is −75-75
  • c. there is no overflow and the result is +181+181
Show the result

a.

Show the full solution

01101001=+10501101001=+105 and 01001100=+7601001100=+76 are both positive, but the sum 181181 exceeds the maximum +127+127: the sum bits 1011010110110101 have the sign bit at 11 (they would read −75-75), 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 (11 here) differs from the carry out of it (00). Answer b. trusts the bits; c. reads the bits as unsigned, but the numbers are signed on 88 bits and 181181 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 F=A B+C‾ DF=A\,B+\overline{C}\,D is:

  • a. (A‾+B‾) (C‾+D)(\overline A+\overline B)\,(\overline C+D)
  • b. (A‾+B‾) (C+D‾)(\overline A+\overline B)\,(C+\overline D)
  • c. A‾ B‾+C D‾\overline A\,\overline B+C\,\overline D
Show the result

b.

Show the full solution

De Morgan: negate every literal and swap sums and products. F‾=AB‾⋅C‾D‾=(A‾+B‾)(C+D‾)\overline F=\overline{AB}\cdot\overline{\overline C D}=(\overline A+\overline B)(C+\overline D). Quick check with A=0,B=0,C=0,D=1A=0,B=0,C=0,D=1: F=0+1⋅1=1F=0+1\cdot1=1, so F‾\overline F must be 00; option b. gives 1⋅(0+0)=01\cdot(0+0)=0 (correct), option a. gives 1⋅(1+1)=11\cdot(1+1)=1 (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 A+A‾ B+A CA+\overline A\,B+A\,C is equivalent to:

  • a. A+BA+B
  • b. A+CA+C
  • c. A+B+CA+B+C
Show the result

a.

Show the full solution

Use X+X‾ Y=X+YX+\overline X\,Y=X+Y (a theorem of Boolean algebra): A+A‾ B=A+BA+\overline A\,B=A+B. Then A CA\,C is absorbed by AA (A+AC=AA+AC=A), so the whole expression is A+BA+B. Check with A=0,B=0,C=1A=0,B=0,C=1: the original is 0+0+0=00+0+0=0, and A+B+CA+B+C would give 11 (option c. is wrong); with A=0,B=1,C=0A=0,B=1,C=0 the original is 11 and A+CA+C would give 00 (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. 22
  • b. 44
  • c. 33
Show the result

c.

Show the full solution

By De Morgan A B=A‾+B‾‾A\,B=\overline{\overline A+\overline B}: two NORs with tied inputs make A‾\overline A and B‾\overline B, and a third NOR combines them. Total 33 gates. Dually the OR needs 22 NOR gates and the AND with NAND gates needs 22; 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. {NAND}\{\text{NAND}\}
  • b. {AND,OR}\{\text{AND},\text{OR}\}
  • c. {NOR}\{\text{NOR}\}
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 00 to 11 can never lower the output), whereas A‾\overline A 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 33 ns. Input AA is 11 between 1010 ns and 4040 ns and 00 otherwise; input BB is 11 between 2525 ns and 6060 ns and 00 otherwise. The output is 11 between:

  • a. 2525 ns and 4040 ns
  • b. 2828 ns and 4040 ns
  • c. 2828 ns and 4343 ns
Show the result

c.

Show the full solution

The ideal output is 11 when both inputs are 11, that is from 2525 to 4040 ns. A real gate reproduces the same waveform shifted by tG=3t_G=3 ns on both edges: it rises at 2828 ns and falls at 4343 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 G1G_1 (1.01.0 ns), G2G_2 (1.51.5 ns), G3G_3 (2.02.0 ns), G4G_4 (2.02.0 ns). G1G_1 feeds G2G_2, G2G_2 feeds G4G_4, and G3G_3 feeds G4G_4; the output is the output of G4G_4 and all the inputs change at the same time. After how long is the output certainly stable?

  • a. 4.54.5 ns
  • b. 8.58.5 ns
  • c. 4.04.0 ns
Show the result

a.

Show the full solution

The delay of the circuit is that of the slowest path (critical path). Path G1→G2→G4G_1\to G_2\to G_4: 1.0+1.5+2.0=4.51.0+1.5+2.0=4.5 ns. Path G3→G4G_3\to G_4: 2.0+2.0=4.02.0+2.0=4.0 ns. The output is stable after 4.54.5 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 (S,R)(S,R) are applied in this order: (0,1)(0,1), (0,0)(0,0), (1,0)(1,0), (0,0)(0,0). The final value of QQ is:

  • a. undefined
  • b. 00
  • c. 11
Show the result

c.

Show the full solution

Quiz 13

Which statement correctly compares a D latch (control input CC) with a positive-edge-triggered D flip-flop?

  • a. both are transparent while the clock is 11
  • b. the latch is transparent while C=1C=1 (its output follows DD), the flip-flop copies DD only at the rising clock edge
  • c. the flip-flop follows DD while the clock is 00, the latch only at the clock edge
Show the result

b.

Show the full solution

A latch is level sensitive: for C=1C=1 it is transparent and QQ follows every change of DD (after the gate delay); for C=0C=0 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 DD reaches QQ only at the active edge, Q(t+1)=D(t)Q(t+1)=D(t). 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 1010 ns and is high in [5,10)[5,10) ns, [15,20)[15,20) ns and so on (it rises at 55 ns). The input DD is 11 only between 66 ns and 88 ns, and 00 at all other times. All the outputs are initially 00 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 11 are:

  • a. flip-flop: always 00; latch: 11 between 66 ns and 88 ns
  • b. flip-flop: 11 from 1515 ns; latch: always 00
  • c. both always 00
Show the result

a.

Show the full solution

The flip-flop looks at DD only at the rising edges (55 ns, 1515 ns, ...): at both instants D=0D=0, so QQ stays 00 (the pulse of DD between 66 and 88 ns falls between two edges and is ignored). The latch is transparent during [5,10)[5,10) ns: from 66 to 88 ns it copies D=1D=1, then follows DD back to 00 at 88 ns; in [10,15)[10,15) it holds 00. So the latch shows a 22 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 S=1S=1 and R=1R=1 are applied. What happens?

  • a. the latch is set: Q=1Q=1 and Q‾=0\overline Q=0
  • b. both outputs go to 00, which violates Q‾=NOT Q\overline Q=\text{NOT }Q, and when the inputs return to 0,00,0 the final state cannot be predicted
  • c. the latch holds its previous value
Show the result

b.

Show the full solution

With S=R=1S=R=1 each NOR has an input at 11, so both outputs become 00: Q=Q‾=0Q=\overline Q=0, which is not a valid pair of complementary values. Moreover, going back to S=R=0S=R=0 the two gates compete and the final state depends on which input falls first and on the gate delays. For this reason S=R=1S=R=1 is forbidden; the D latch removes the problem by imposing S=DS=D, R=D‾R=\overline D. 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 259259 written in BCD is:

  • a. 100000011100000011
  • b. 0001 0000 00110001\ 0000\ 0011
  • c. 0010 0101 10010010\ 0101\ 1001
Show the result

c.

Show the full solution

Quiz 17

A pipelined processor has 44 stages (IF, DOF, EX, WB) and executes 1212 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. 1515
  • b. 1212
  • c. 4848
Show the result

a.

Show the full solution

With kk stages and NN instructions the cycles are k+N−1k+N-1: the first instruction needs k=4k=4 cycles, then one more instruction completes every cycle, so 4+12−1=154+12-1=15. Answer b. forgets the filling of the pipeline; answer c. is the count of a processor that executes one instruction at a time in 44 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 44-stage pipeline (IF, DOF, EX, WB) the register R1R_1 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

  1. R1←R2+R3R_1\leftarrow R_2+R_3
  2. R4←R1+R5R_4\leftarrow R_1+R_5

If the hardware solves the data hazard with a stall, instruction 2 is delayed by:

  • a. 00 cycles
  • b. 22 cycles
  • c. 11 cycle
Show the result

c.

Show the full solution

Instruction 1 does IF, DOF, EX, WB in cycles 1,2,3,41,2,3,4; instruction 2 would do its DOF at cycle 33, but R1R_1 is written only at cycle 44 (first half): at cycle 33 it would read the old value, so there is a data hazard. Delaying the DOF by one cycle (DOF at cycle 44, 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 R1R_1 were written in the second half of WB, so that the read could happen only at cycle 55. 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 1616 lines, one word per line. The main memory is addressed with 1212-bit word addresses. How many bits does the tag have?

  • a. 44
  • b. 1212
  • c. 88
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. 16=2416=2^4 lines need a 44-bit index, so the tag has 12−4=812-4=8 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 11 ns, a miss rate of 4%4\% and a miss penalty of 6060 ns. The average access time is:

  • a. 3.43.4 ns
  • b. 2.42.4 ns
  • c. 6161 ns
Show the result

a.

Show the full solution

tavg=thit+miss rate⋅tpenalty=1+0.04⋅60=1+2.4=3.4t_{avg}=t_{hit}+\text{miss rate}\cdot t_{penalty}=1+0.04\cdot60=1+2.4=3.4 ns. Answer b. is only the contribution of the misses (the hit time is always paid); c. is the access time of a miss (1+601+60), which happens only 4%4\% 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 NN from 00 to 1313, written in binary on four bits d c b ad\,c\,b\,a (dd is the most significant bit). The values 1414 and 1515 never occur at the input. The output PP is 11 if NN is a prime number (2,3,5,7,11,132,3,5,7,11,13) and 00 otherwise (the numbers 00 and 11 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 PP. 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 1.21.2 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 N=14N=14 and N=15N=15? Is it a problem?

Show the result

a) P=1P=1 for N=2,3,5,7,11,13N=2,3,5,7,11,13; P=0P=0 for N=0,1,4,6,8,9,10,12N=0,1,4,6,8,9,10,12; don't care (X) for N=14,15N=14,15. b) P=a b+a c+d‾ c‾ bP=a\,b+a\,c+\overline d\,\overline c\,b (three products, 77 literals; the minimum is unique). c) P=a b‾⋅a c‾⋅d‾ c‾ b‾‾P=\overline{\overline{a\,b}\cdot\overline{a\,c}\cdot\overline{\overline d\,\overline c\,b}}: two 2-input NANDs, two 3-input NANDs (2+2+3+3=102+2+3+3=10 inputs) and two inverters made of NANDs (dd and cc): 66 NAND gates in total (1414 gate inputs counting each tied NAND as a 2-input gate). d) 3.63.6 ns (path dd or c→c\to inverter →\to 3-input NAND →\to 3-input NAND); the other paths take 2.42.4 ns. e) P(14)=0P(14)=0 and P(15)=1P(15)=1: 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 NN, so the minterm of NN 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 →):

NN d c b ad\,c\,b\,a PP NN d c b ad\,c\,b\,a PP
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 d cd\,c and the columns b ab\,a in Gray code order (00,01,11,1000,01,11,10), so that adjacent cells differ by one bit; in brackets the value of NN (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 →):

dc\badc\backslash ba 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 11s in rectangles of 2k2^k adjacent cells, as large as possible; the X cells may be used as 11 when they enlarge a group (never a group made only of X).

  • Column ba=11ba=11 (cells 3,7,15,113,7,15,11; the 1515 is an X): a=1a=1, b=1b=1 fixed, dd and cc vary: a ba\,b. It covers 3,7,113,7,11.
  • Block of rows 01,1101,11 and columns 01,1101,11 (cells 5,7,13,155,7,13,15; again the X in 1515): a=1a=1 and c=1c=1 fixed: a ca\,c. It covers 5,135,13 (and 77).
  • The cell 22 (00100010) is covered only by the pair {2,3}\{2,3\}: row 0000, columns 1111 and 1010: d=0,c=0,b=1d=0,c=0,b=1 fixed: d‾ c‾ b\overline d\,\overline c\,b. It cannot be enlarged: the cells that would complete a rectangle of four, 66 and 1010, are 00.

All three groups are essential (the cell 22 only by the third, 1111 only by a ba\,b, 1313 only by a ca\,c), and together they cover all the 11s, so the minimum is unique: P=a b+a c+d‾ c‾ b.P=a\,b+a\,c+\overline d\,\overline c\,b. Check on all the values from 00 to 1313: the expression is 11 exactly for 2,3,5,7,11,132,3,5,7,11,13 (22: third product; 3,113,11: a ba\,b; 5,135,13: a ca\,c; 77: both a ba\,b and a ca\,c) and 00 for the others (for example 1=00011=0001: a b=0a\,b=0, a c=0a\,c=0, d‾ c‾ b=0\overline d\,\overline c\,b=0 because b=0b=0).

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: P=ab‾⋅ac‾⋅d‾ c‾ b‾‾P=\overline{\overline{ab}\cdot\overline{ac}\cdot\overline{\overline d\,\overline c\,b}}. There is one NAND for each product and a final NAND with as many inputs as products:

Count: 44 gates with 2+2+3+3=102+2+3+3=10 inputs, plus the 22 inverters: 66 gates, 1414 inputs if each tied NAND is counted as a 2-input gate (1212 if an inverter is counted as a one-input gate). The variables aa and bb appear only in direct form and need no inverter.

Part d: delay. Every gate has 1.21.2 ns, so the delay of a path is 1.21.2 ns times the number of gates crossed. Path from aa or bb: G1G_1 or G2G_2 or G3G_3, then the output NAND: 22 gates, 2.42.4 ns. Path from dd or cc: inverter, G3G_3, output NAND: 33 gates, 3×1.2=3.63\times1.2=3.6 ns. The output is certainly stable after the slowest path, 3.63.6 ns. (Typical mistake: forgetting that the inverters add a level in the paths of cc and dd.)

Part e. For N=14=1110N=14=1110: a b=0a\,b=0 (a=0a=0), a c=0a\,c=0, d‾ c‾ b=0\overline d\,\overline c\,b=0 (d=1d=1): P=0P=0. For N=15=1111N=15=1111: a b=1a\,b=1, so P=1P=1. These values are not required (they are "don't care") because 1414 and 1515 never occur: using the X as 11 in the cell 1515 is exactly what allowed the bigger groups a ba\,b and a ca\,c; the X in 1414 was left as 00.

Typical mistakes: grouping the X cells alone; not using the X cell 1515 and so leaving smaller groups (for example d‾ b a\overline d\,b\,a instead of a ba\,b); 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 XX (a new bit at every clock cycle) and an output ZZ, following the Mealy model, that recognises the sequence 01100110 in the bits received. Z=1Z=1 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 0,1,1,00,1,1,0; Z=0Z=0 otherwise. Overlapping sequences are allowed (with the input 01101100110110 the output is 11 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 S0=00S_0=00, S1=01S_1=01, S2=11S_2=11, S3=10S_3=10 for Q1Q0Q_1Q_0 and write the table of the next state and of the output. c) Derive with Karnaugh maps the minimum equations of D1D_1, D0D_0 and ZZ. d) For the input X=1,0,0,1,1,0,1,1,0,0,0,1,1,0X=1,0,0,1,1,0,1,1,0,0,0,1,1,0 (one bit per cycle, starting from S0S_0) give for every cycle the present state, the output ZZ and the next state. e) Add a synchronous reset rstrst (active high) that brings the circuit to S0S_0: how do the equations of the flip-flops change?

Show the result

a) Four states, all distinguishable. S0S_0: no useful prefix; S1S_1: the bits end with 00; S2S_2: they end with 0101; S3S_3: they end with 011011. Next state / ZZ for X=0X=0 and X=1X=1: S0S_0: S1/0S_1/0, S0/0S_0/0; S1S_1: S1/0S_1/0, S2/0S_2/0; S2S_2: S1/0S_1/0, S3/0S_3/0; S3S_3: S1/1S_1/1, S0/0S_0/0. Z=1Z=1 only in S3S_3 with X=0X=0. b) 22 flip-flops (no unused code). c) D1=Q0 XD_1=Q_0\,X; D0=X‾+Q1‾ Q0D_0=\overline X+\overline{Q_1}\,Q_0; Z=Q1 Q0‾ X‾Z=Q_1\,\overline{Q_0}\,\overline X. d) Present states S0,S0,S1,S1,S2,S3,S1,S2,S3,S1,S1,S1,S2,S3S_0,S_0,S_1,S_1,S_2,S_3,S_1,S_2,S_3,S_1,S_1,S_1,S_2,S_3; Z=0,0,0,0,0,1,0,0,1,0,0,0,0,1Z=0,0,0,0,0,1,0,0,1,0,0,0,0,1 (so Z=1Z=1 in cycles 66, 99, 1414); next states S0,S1,S1,S2,S3,S1,S2,S3,S1,S1,S1,S2,S3,S1S_0,S_1,S_1,S_2,S_3,S_1,S_2,S_3,S_1,S_1,S_1,S_2,S_3,S_1. e) D1=rst‾ Q0 XD_1=\overline{rst}\,Q_0\,X and D0=rst‾ (X‾+Q1‾ Q0)D_0=\overline{rst}\,(\overline X+\overline{Q_1}\,Q_0): an AND with rst‾\overline{rst} on each DD input; ZZ 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 01100110 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 01100110 (this rule gives the overlaps).

  • S0S_0: no tail of the received bits is a prefix of 01100110 (the start, or after a 11 that does not continue a prefix).
  • S1S_1: the bits end with 00 (prefix of length 11).
  • S2S_2: the bits end with 0101 (prefix of length 22).
  • S3S_3: the bits end with 011011 (prefix of length 33).

Transitions:

  • S0S_0, X=0X=0: the 00 starts a prefix, go to S1S_1; X=1X=1: a 11 is not a prefix, stay in S0S_0.
  • S1S_1, X=0X=0: …00\dots00 ends with 00, still a prefix of length 11: stay in S1S_1; X=1X=1: …01\dots01, go to S2S_2.
  • S2S_2, X=0X=0: …010\dots010: of its tails (00, 1010, 010010) only 00 is a prefix of 01100110, go to S1S_1; X=1X=1: …011\dots011, go to S3S_3.
  • S3S_3, X=0X=0: sequence 01100110 completed, so Z=1Z=1; the last 00 can start a new sequence (overlap) and the next state is S1S_1; X=1X=1: …0111\dots0111 has no tail that is a prefix, go to S0S_0.

State table (next state / ZZ; in a Mealy machine the output is written on the transition):

present state X=0X=0 X=1X=1
S0S_0 S1/0S_1/0 S0/0S_0/0
S1S_1 S1/0S_1/0 S2/0S_2/0
S2S_2 S1/0S_1/0 S3/0S_3/0
S3S_3 S1/1S_1/1 S0/0S_0/0

The diagram is redrawn with four circles S0,…,S3S_0,\dots,S_3 and eight arrows labelled X/ZX/Z: S0→0/0S1S_0\xrightarrow{0/0}S_1, S0→1/0S0S_0\xrightarrow{1/0}S_0 (loop), S1→0/0S1S_1\xrightarrow{0/0}S_1 (loop), S1→1/0S2S_1\xrightarrow{1/0}S_2, S2→0/0S1S_2\xrightarrow{0/0}S_1, S2→1/0S3S_2\xrightarrow{1/0}S_3, S3→0/1S1S_3\xrightarrow{0/1}S_1, S3→1/0S0S_3\xrightarrow{1/0}S_0.

No equivalent states. Two states are equivalent if no input sequence can tell them apart by the outputs. S3S_3 is the only state that gives Z=1Z=1 at once (with X=0X=0), so it differs from all the others. S2S_2 is told from S0S_0 and S1S_1 by the input 1,01,0: from S2S_2 it gives Z=1Z=1 at the second bit, from S0S_0 and S1S_1 it does not. S0S_0 and S1S_1 are told apart by 1,1,01,1,0: from S1S_1 it goes S2,S3S_2,S_3 and gives Z=1Z=1, from S0S_0 it does not. So 44 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. 2m≥42^m\ge4 gives m=2m=2 flip-flops, Q1Q0Q_1Q_0, and all four codes are used (there are no don't care combinations). The encoding is a Gray sequence along the main path S0→S1→S2→S3S_0\to S_1\to S_2\to S_3. For a D flip-flop the next state bits are directly the DD inputs:

Q1Q0Q_1Q_0 (state) XX D1D0D_1D_0 (next state) ZZ
00 (S0S_0) 0 01 0
00 1 00 0
01 (S1S_1) 0 01 0
01 1 11 0
11 (S2S_2) 0 01 0
11 1 10 0
10 (S3S_3) 0 01 1
10 1 00 0

Part c: equations. Maps with rows Q1Q0Q_1Q_0 in Gray order and columns XX (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 →):

D1D_1:

Q1Q0\XQ_1Q_0\backslash X 0 1
00 0 0
01 0 1
11 0 1
10 0 0

D1=1D_1=1 only in the two cells with Q0=1Q_0=1 and X=1X=1: D1=Q0 XD_1=Q_0\,X.

D0D_0:

Q1Q0\XQ_1Q_0\backslash X 0 1
00 1 0
01 1 1
11 1 0
10 1 0

The whole column X=0X=0 (four cells): X‾\overline X. The cell (01,X=1)(01,X=1) is joined with the cell (01,X=0)(01,X=0): the pair with Q1=0Q_1=0, Q0=1Q_0=1: Q1‾ Q0\overline{Q_1}\,Q_0. So D0=X‾+Q1‾ Q0D_0=\overline X+\overline{Q_1}\,Q_0.

ZZ: it is 11 only in the cell (10,X=0)(10,X=0), whose neighbours are all 00 and which cannot be enlarged: Z=Q1 Q0‾ X‾Z=Q_1\,\overline{Q_0}\,\overline X. Since ZZ depends on XX as well as on the state, the machine is Mealy and ZZ changes as soon as XX changes, within the cycle.

Part d: trace. At every cycle the present state and XX give ZZ (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
XX 1 0 0 1 1 0 1 1 0 0 0 1 1 0
present state S0S_0 S0S_0 S1S_1 S1S_1 S2S_2 S3S_3 S1S_1 S2S_2 S3S_3 S1S_1 S1S_1 S1S_1 S2S_2 S3S_3
ZZ 0 0 0 0 0 1 0 0 1 0 0 0 0 1
next state S0S_0 S1S_1 S1S_1 S2S_2 S3S_3 S1S_1 S2S_2 S3S_3 S1S_1 S1S_1 S1S_1 S2S_2 S3S_3 S1S_1

Z=1Z=1 in cycles 66, 99 and 1414: the bits 0,1,1,00,1,1,0 are at cycles 33 to 66, then 66 to 99 (the last 00 of the first sequence is also the first 00 of the second: overlap) and 1111 to 1414.

Part e: synchronous reset. A synchronous reset acts only at a clock edge and forces the state to S0=00S_0=00: it is realised with an AND with rst‾\overline{rst} in front of each DD input. D1=rst‾ Q0 XD_1=\overline{rst}\,Q_0\,X and D0=rst‾ (X‾+Q1‾ Q0)D_0=\overline{rst}\,(\overline X+\overline{Q_1}\,Q_0). The output ZZ is unchanged (it depends only on the present state and on XX). With rst=1rst=1 both DD become 00 and at the next edge the circuit is in S0S_0 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 S0S_0 instead of S1S_1 after the complete sequence (this loses the overlap); going from S2S_2 with X=0X=0 to S0S_0 instead of S1S_1 (the last 00 is a prefix); reading ZZ 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 xx, clock clkclk and synchronous reset rstrst (active high), output zz (all std_logic). The states are S0,…,S3S_0,\dots,S_3 and the machine is a Mealy machine with the following table (next state / zz):

present state x=0x=0 x=1x=1
S0S_0 S1/0S_1/0 S0/0S_0/0
S1S_1 S1/0S_1/0 S2/0S_2/0
S2S_2 S1/0S_1/0 S3/0S_3/0
S3S_3 S1/1S_1/1 S0/0S_0/0

The code must separate the memory element (state register) from the purely combinational parts.

  1. Write entity and architecture of the machine.
  2. Write a test bench (empty entity, clock of period 1010 ns starting at '0', inputs changing on the falling edge of the clock) that applies, one value per clock cycle: cycle 11: rst='1', x='0'; then, with rst='0', the 1515 bits 1,0,1,1,1,0,0,1,0,1,1,0,1,1,01,0,1,1,1,0,0,1,0,1,1,0,1,1,0 (one per cycle).
  3. Give the state after each rising clock edge and the times at which z=1z=1. Does the test sequence go through all the transitions of the table?
Show the result
  1. Three processes: state register (clock edge, synchronous reset tested inside the edge branch, state <= next_state), next state (case state, sensitive to state and x), output (z equal to '1' only in S3 with x='0', sensitive to state and x).
  2. Test bench with clock process, input process (reset in cycle 11, then the 1515 bits in a loop with wait for PERIOD) and std.env.stop.
  3. State after the rising edges: S0S_0 (reset at 55 ns), then, after the 1515 bits, S0,S1,S2,S3,S0,S1,S1,S2,S1,S2,S3,S1,S2,S3,S1S_0,S_1,S_2,S_3,S_0,S_1,S_1,S_2,S_1,S_2,S_3,S_1,S_2,S_3,S_1. z=1z=1 for 55 ns from 120120 ns (bit 1212) and from 150150 ns (bit 1515). Yes: all the 88 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.

vhdl
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 →):

vhdl
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 55 ns sees rst='1' and brings the state to S0S_0 (the declaration also gives the initial value S0S_0). The bit number i+1i+1 is applied at the falling edge 10+10 i10+10\,i ns and sampled at the rising edge 15+10 i15+10\,i 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 S0S_0 S0S_0 S1S_1 S2S_2 S3S_3 S0S_0 S1S_1 S1S_1 S2S_2 S1S_1 S2S_2 S3S_3 S1S_1 S2S_2 S3S_3
z 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1
state after the edge S0S_0 S1S_1 S2S_2 S3S_3 S0S_0 S1S_1 S1S_1 S2S_2 S1S_1 S2S_2 S3S_3 S1S_1 S2S_2 S3S_3 S1S_1

So the states after the rising edges at 55 ns, 1515 ns, ... are S0S_0 (reset), then S0,S1,S2,S3,S0,S1,S1,S2,S1,S2,S3,S1,S2,S3,S1S_0,S_1,S_2,S_3,S_0,S_1,S_1,S_2,S_1,S_2,S_3,S_1,S_2,S_3,S_1. The output is 11 for the bits 1212 (the bits 99 to 1212 are 0,1,1,00,1,1,0) and 1515 (the bits 1212 to 1515 are 0,1,1,00,1,1,0, overlapping with the previous one on the common 00). Since the machine is Mealy, z rises as soon as x changes (at the falling edge, 120120 ns and 150150 ns) and falls at the next rising edge (125125 ns and 155155 ns), when the state leaves S3S_3: it is 11 for 55 ns, and a circuit that uses it samples it at that same rising edge, just before it falls.

The pairs (state, input) visited are (S0,1)(S_0,1), (S0,0)(S_0,0), (S1,1)(S_1,1), (S2,1)(S_2,1), (S3,1)(S_3,1), (S1,0)(S_1,0), (S2,0)(S_2,0), (S3,0)(S_3,0): all 88, 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 0.30.3, so leave blank only if really uncertain hexadecimal grouped from the left, no +1+1 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 k+N−1k+N-1 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 14,1514,15 X used wrongly, wrong Gray order of the columns
Ex. 1, part b 4 P=a b+a c+d‾ c‾ bP=a\,b+a\,c+\overline d\,\overline c\,b with the three groups drawn on the map groups made only of X, group {2,3}\{2,3\} missing, non-minimal cover
Ex. 1, parts c and d 3 NAND-NAND network with 66 gates (inverters from tied NANDs), 1414 inputs, 3.63.6 ns inverters forgotten, delay computed on the wrong path
Ex. 1, part e 1 P(14)=0P(14)=0, P(15)=1P(15)=1, explained as don't care none
Ex. 2, parts a and b 4 four states with meaning, table with overlaps, 22 flip-flops, encoding table Moore instead of Mealy, no overlap, S2S_2 with X=0X=0 to S0S_0
Ex. 2, part c 3 D1=Q0XD_1=Q_0X, D0=X‾+Q1‾Q0D_0=\overline X+\overline{Q_1}Q_0, Z=Q1Q0‾X‾Z=Q_1\overline{Q_0}\overline X non-maximal groups, ZZ without XX
Ex. 2, parts d and e 3 trace with Z=1Z=1 in cycles 6,9,146,9,14; rst‾\overline{rst} on the DD inputs ZZ read in the next state, reset on ZZ
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 1515 bits, std.env.stop inputs on the rising edge, no reset, no end
Ex. 3, part 3 3 states after each edge, z=1z=1 at bits 1212 and 1515, all 88 pairs covered counting the Mealy output one cycle late