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

Digital Systems - Mock Exam 3

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 written exams of the equivalent course in Italian (Circuiti Digitali, Information Engineering, UniPD; sessions of 21 June 2022 and 11 July 2022). The real papers have 20 multiple-choice questions on the whole syllabus (correct answer +1+1, wrong answer −0.3-0.3, no answer 00) and 3 exercises on separate sheets: (1) minimization of a function with Karnaugh maps, (2) design of a finite state machine, (3) VHDL of a state machine with a test bench. This mock keeps the same structure. Because the course in English also covers computer organisation and memory, 4 of the 20 questions (17 to 20) are on addressing modes and virtual memory.

Duration: 2 hours 30 minutes. The real papers do not print the points of the exercises: here they are proposed as questions 2020 points, Exercise 1 1010 points, Exercise 2 1010 points, Exercise 3 1010 points (total 5050, grade out of 30 == points × 30/50\times\,30/50). No material is allowed: no books, notes, calculators or phones. This mock is centred on codes, CMOS technology, programmable logic, RTL, datapath and control unit.


Quiz 1

The binary number 11011101 is converted into the Gray code (most significant bit on the left). The result is:

  • a. 01110111
  • b. 11101110
  • c. 10111011
Show the result

c.

Show the full solution

The conversion rule copies the most significant bit and then computes gi=bi⊕bi+1g_i=b_i\oplus b_{i+1}: g3=1g_3=1, g2=1⊕1=0g_2=1\oplus1=0, g1=1⊕0=1g_1=1\oplus0=1, g0=0⊕1=1g_0=0\oplus1=1, so g=1011g=1011. Check on the table of the 4-bit Gray code: the number 1313 has Gray code 10111011. Choice a comes from XOR-ing each bit with the bit on its right (b⊕b\oplus shifted left), the wrong direction; choice b is the Gray code of 10111011, i.e. input and output exchanged. 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 2

Words of 8 bits (7 data bits plus 1 parity bit) are transmitted with even parity. Which of the following received words certainly contains an error?

  • a. 1011011010110110
  • b. 1100110011001100
  • c. 0000000000000000
Show the result

a.

Show the full solution

With even parity the number of 1s in the whole word, parity bit included, must be even. 1011011010110110 has five 1s: odd, so at least one bit is wrong. 1100110011001100 has four 1s and 0000000000000000 has none: both are acceptable (parity detects errors on an odd number of bits, so two compensating errors would go unnoticed, but these words show no sign of error). Typical mistake: saying that parity can also locate and correct the wrong bit. 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 3

A cyclic Gray code for 1010 words is built by taking the code of the first five words, 0000,0001,0011,0010,01100000,0001,0011,0010,0110, and appending their mirror image with the most significant bit set to 11. The word that follows 01100110 is:

  • a. 01110111
  • b. 11101110
  • c. 10101010
Show the result

b.

Show the full solution

The mirror image of the first five words, in reverse order and with the MSB at 11, is 1110,1010,1011,1001,10001110,1010,1011,1001,1000. So after 01100110 (the last word of the first half) comes 11101110, which differs from 01100110 in one bit only (the MSB), as a Gray code requires; the code is also cyclic because 10001000 and 00000000 differ by one bit. Choice a is the word that follows 01100110 in the full 44-bit Gray code of 1616 words, which is not the code asked. Choice c is the second word of the reflected half and differs from 01100110 in three bits. 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 4

Let clk, rst, en, d, q be std_logic signals. The VHDL fragment

vhdl
process (clk, rst)
begin
  if rst = '0' then
    q <= '0';
  elsif clk'event and clk = '1' then
    if en = '1' then q <= d; end if;
  end if;
end process;

describes:

  • a. a D latch with enable en and active-low clear
  • b. a positive-edge-triggered flip-flop with asynchronous active-low reset and load enable
  • c. a positive-edge-triggered flip-flop with synchronous reset
Show the result

b.

Show the full solution

rst is in the sensitivity list and is tested first, outside the branch of the clock edge: the reset acts at any time, without waiting for the clock (asynchronous), and it is active at '0'. The condition clk'event and clk = '1' is the rising edge, so the element is edge-triggered, not a latch (a latch would be level-sensitive and have d in the list). Inside the edge, if en = '1' without else makes the register hold its value when en = '0': this is the load enable. For a synchronous reset, rst would be missing from the list and tested inside the edge branch. Theory: 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 →, Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →.

Quiz 5

In a static CMOS 3-input NOR gate the inputs are A=1A=1, B=0B=0, C=0C=0. How many transistors conduct and what is the output QQ?

  • a. 11 nMOS and 22 pMOS conduct, Q=0Q=0
  • b. 22 nMOS and 11 pMOS conduct, Q=0Q=0
  • c. 11 nMOS and 22 pMOS conduct, Q=1Q=1
Show the result

a.

Show the full solution

An nMOS conducts when its gate is 11, a pMOS when its gate is 00. With A=1,B=0,C=0A=1,B=0,C=0: the nMOS of AA conducts (11 nMOS) and the pMOS of BB and CC conduct (22 pMOS). In the NOR the pull-up network is three pMOS in series: it needs all three on, but the pMOS of AA is off, so the pull-up is open. The pull-down network is three nMOS in parallel: the nMOS of AA is on, so the output is connected to ground, Q=0Q=0 (indeed 1+0+0‾=0\overline{1+0+0}=0). Choice b swaps the roles of nMOS and pMOS; choice c has the right count of devices but the wrong output: the two networks are never both on or both off. Theory: CMOS Gates and Technology ParametersIn CMOS integrated circuits MOSFETs are modelled as switches: nMOS closed when the gate is 1, pMOS closed when the gate is 0. A static gate has a pull-up network (only pMOS, to Vdd) and a dual pull-down network (only nMOS, to ground): one is ON and the other OFF. NAND has series nMOS and parallel pMOS, NOR the opposite; an n-input gate has 2n transistors. Real-gate parameters: fan-in, fan-out, noise margin, propagation delay, power dissipation and cost.CMOS Gates and Technology Parameters →.

Quiz 6

A 4-input AND gate is built in static CMOS as a NAND followed by an inverter. The number of transistors is:

  • a. 88
  • b. 1212
  • c. 1010
Show the result

c.

Show the full solution

A NAND (or NOR) with nn inputs has 2n2n transistors (nn nMOS and nn pMOS): 2⋅4=82\cdot4=8 for the 4-input NAND. The inverter adds 22 transistors: 8+2=108+2=10 (formula 2n+22n+2). Choice a forgets the inverter; this is also why AND and OR gates cost more than NAND and NOR, and circuits are normally mapped on NAND and NOR. Theory: CMOS Gates and Technology ParametersIn CMOS integrated circuits MOSFETs are modelled as switches: nMOS closed when the gate is 1, pMOS closed when the gate is 0. A static gate has a pull-up network (only pMOS, to Vdd) and a dual pull-down network (only nMOS, to ground): one is ON and the other OFF. NAND has series nMOS and parallel pMOS, NOR the opposite; an n-input gate has 2n transistors. Real-gate parameters: fan-in, fan-out, noise margin, propagation delay, power dissipation and cost.CMOS Gates and Technology Parameters →, Implementation Technologies - CMOS Gates and Technology ParametersIn CMOS integrated circuits MOSFETs behave as switches: an nMOS conducts when its gate is 1, a pMOS when its gate is 0. A static gate has a pull-up network (only pMOS, to Vdd) and a dual pull-down network (only nMOS, to ground), exactly one of which is on. NAND has series nMOS and parallel pMOS, NOR the opposite; an n-input NAND or NOR has 2n transistors. Technology parameters are fan-in, fan-out, noise margin, propagation delay (limits clock frequency), power dissipation and cost (silicon area, NRE and production costs).Implementation Technologies - CMOS Gates and Technology Parameters →.

Quiz 7

The dynamic power dissipated by a CMOS circuit is P≈αCVdd2fP\approx\alpha C V_{dd}^2 f. If the supply voltage is halved while the clock frequency and the circuit stay the same, the power becomes:

  • a. one half
  • b. one quarter
  • c. unchanged
Show the result

b.

Show the full solution

PP grows with the square of VddV_{dd}: with Vdd′=Vdd/2V_{dd}'=V_{dd}/2 we get P′=αC(Vdd/2)2f=P/4P'=\alpha C (V_{dd}/2)^2f=P/4. Choice a would hold if PP were proportional to VddV_{dd} (as it is to ff). Lowering the voltage is the most effective way of reducing power, at the price of slower gates (a larger delay and so a lower maximum frequency). Theory: CMOS Gates and Technology ParametersIn CMOS integrated circuits MOSFETs are modelled as switches: nMOS closed when the gate is 1, pMOS closed when the gate is 0. A static gate has a pull-up network (only pMOS, to Vdd) and a dual pull-down network (only nMOS, to ground): one is ON and the other OFF. NAND has series nMOS and parallel pMOS, NOR the opposite; an n-input gate has 2n transistors. Real-gate parameters: fan-in, fan-out, noise margin, propagation delay, power dissipation and cost.CMOS Gates and Technology Parameters →.

Quiz 8

The two functions F1=AB+CDF_1=AB+CD and F2=AB+C‾ D‾F_2=AB+\overline C\,\overline D are to be implemented. How many product terms (AND gates of the AND array) are needed in a PLA and in a PAL, respectively?

  • a. 33 and 44
  • b. 44 and 33
  • c. 33 and 33
Show the result

a.

Show the full solution

The distinct products are ABAB, CDCD and C‾ D‾\overline C\,\overline D. In a PLA both arrays are programmable and a product can be shared between outputs: ABAB is generated once and enters both ORs, so 33 products are enough. In a PAL the OR array is fixed and every output has its own ANDs: F1F_1 needs ABAB and CDCD, F2F_2 needs ABAB again and C‾ D‾\overline C\,\overline D, so 2+2=42+2=4 products. Typical mistake: believing that the PAL can share products too. Theory: Programmable Logic Devices - ROM, PLA, PAL and FPGAProgrammable logic devices (PLD) have logic structures configurable by the manufacturer or the user, which is hardware configuration and not software programming. ROM: 2^k words of n bits, a decoder followed by programmable ORs, so a physical truth table; PLA: programmable AND and OR arrays with product terms shared between outputs; PAL: programmable ANDs and fixed ORs, no sharing; FPGA: programmable logic blocks with look-up tables and flip-flops, programmable routing and I/O, with a volatile or non-volatile configuration memory. Programming is irreversible (fuse, anti-fuse, mask) or reconfigurable (SRAM, floating gate).Programmable Logic Devices - ROM, PLA, PAL and FPGA →.

Quiz 9

A ROM has 1212 address inputs and 1616 data outputs. Its capacity in bytes is:

  • a. 40964096
  • b. 65 53665\,536
  • c. 81928192
Show the result

c.

Show the full solution

A ROM 2k×n2^k\times n has 2k2^k words of nn bits. Here 212=40962^{12}=4096 words of 1616 bits, i.e. 4096⋅16=65 5364096\cdot16=65\,536 bits, and dividing by 88: 81928192 bytes (equivalently, 40964096 words of 22 bytes). Choice a is the number of words, choice b the number of bits. Theory: Programmable Logic Devices - ROM, PLA, PAL and FPGAProgrammable logic devices (PLD) have logic structures configurable by the manufacturer or the user, which is hardware configuration and not software programming. ROM: 2^k words of n bits, a decoder followed by programmable ORs, so a physical truth table; PLA: programmable AND and OR arrays with product terms shared between outputs; PAL: programmable ANDs and fixed ORs, no sharing; FPGA: programmable logic blocks with look-up tables and flip-flops, programmable routing and I/O, with a volatile or non-volatile configuration memory. Programming is irreversible (fuse, anti-fuse, mask) or reconfigurable (SRAM, floating gate).Programmable Logic Devices - ROM, PLA, PAL and FPGA →, Memories - ROM, RAM, SRAM and DRAMA memory is a set of cells organised in words, with control circuitry. It is classified as read-only (ROM) or read/write, random access (RAM), serial (SAM) or hybrid (Flash), volatile (SRAM, DRAM) or non-volatile. A RAM 2^k x n has k address bits (independent of n), n data bits, read/write and chip select. SRAM uses a bistable latch cell, is fast and needs no refresh; DRAM stores charge on a capacitor, is denser and needs refresh. Chips are organised as a row/column matrix with coincident selection and tri-state outputs, and combined in arrays for more words or more bits per word.Memories - ROM, RAM, SRAM and DRAM →.

Quiz 10

A look-up table (LUT) with 44 inputs, as used in the logic blocks of an FPGA, needs how many configuration bits?

  • a. 44
  • b. 1616
  • c. 6464
Show the result

b.

Show the full solution

Quiz 11

The following microoperations are specified in RTL (both conditions can be 11 in the same cycle): K1: R0←R1,K1‾ K2: R0←R2.K_1:\ R_0\leftarrow R_1,\qquad \overline{K_1}\,K_2:\ R_0\leftarrow R_2 . At a clock edge with K1=1K_1=1, K2=1K_2=1, R1=0101R_1=0101 and R2=1010R_2=1010, the register R0R_0 becomes:

  • a. 01010101
  • b. 10101010
  • c. 11111111
Show the result

a.

Show the full solution

The second condition contains K1‾\overline{K_1}: it is 00 when K1=1K_1=1, so the second transfer does not take place. The two statements behave as an if-then-else with priority to K1K_1: R0←R1=0101R_0\leftarrow R_1=0101. In the circuit a multiplexer selects the source and Load=K1+K2Load=K_1+K_2 enables the loading. Choice c would be the logical OR of the two sources, which is not what a conditional transfer does. Theory: Microoperations and RTLA microoperation is an elementary operation on register data, written in Register Transfer Language (RTL), for example K1: R2 <- R1 meaning that when K1 is 1 the content of R1 is copied into R2 at the clock edge. Microoperations are transfers (simultaneous ones separated by commas exchange contents), arithmetic (add, subtract, increment, decrement), logic bit by bit with masks (AND clears, OR sets to 1, XOR complements) and shifts (sl towards the MSB doubles, sr towards the LSB halves).Microoperations and RTL →, Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →.

Quiz 12

An 8-bit register contains R=10110110R=10110110. The microoperation R←R⊕11110000R\leftarrow R\oplus 11110000 (bitwise XOR with a mask) gives:

  • a. 1011000010110000
  • b. 0100011001000110
  • c. 1111011011110110
Show the result

b.

Show the full solution

XOR with 11 complements the bit, XOR with 00 leaves it unchanged. The mask 1111000011110000 complements the four most significant bits and keeps the four least significant: 1011→01001011\to0100, 0110→01100110\to0110, so R=01000110R=01000110. Choice a is the result of an AND with the mask (it clears the low nibble), choice c of an OR (it sets the high nibble to 11). Theory: Microoperations and RTLA microoperation is an elementary operation on register data, written in Register Transfer Language (RTL), for example K1: R2 <- R1 meaning that when K1 is 1 the content of R1 is copied into R2 at the clock edge. Microoperations are transfers (simultaneous ones separated by commas exchange contents), arithmetic (add, subtract, increment, decrement), logic bit by bit with masks (AND clears, OR sets to 1, XOR complements) and shifts (sl towards the MSB doubles, sr towards the LSB halves).Microoperations and RTL →.

Quiz 13

The 8-bit register R=01001100R=01001100 (unsigned value 7676) executes the shift microoperation R←sl RR\leftarrow sl\,R (shift left, the bit entering on the right is 00). The new content is:

  • a. 0010011000100110
  • b. 1001100110011001
  • c. 1001100010011000
Show the result

c.

Show the full solution

A shift left moves every bit one position towards the MSB; the bit that leaves is the leftmost (00 here) and a 00 enters on the right: 01001100→1001100001001100\to10011000, which is 152=2⋅76152=2\cdot76. A shift left multiplies by 22 as long as no significant bit is lost (here the leaving bit was 00). Choice a is the shift right (76/2=3876/2=38); choice b enters a 11 instead of a 00. Theory: Microoperations and RTLA microoperation is an elementary operation on register data, written in Register Transfer Language (RTL), for example K1: R2 <- R1 meaning that when K1 is 1 the content of R1 is copied into R2 at the clock edge. Microoperations are transfers (simultaneous ones separated by commas exchange contents), arithmetic (add, subtract, increment, decrement), logic bit by bit with masks (AND clears, OR sets to 1, XOR complements) and shifts (sl towards the MSB doubles, sr towards the LSB halves).Microoperations and RTL →, Shift Registers and CountersA shift register is a chain of D flip-flops, each output feeding the next input, so bits move one position per clock edge; it has serial input and output, optional parallel load (Shift has priority over Load) and a bidirectional version with a 4-to-1 MUX per stage (S1S0: 00 hold, 01 shift left, 10 shift right, 11 load). Uses: serial/parallel conversion, serial interfaces, delay lines, pseudo-random generators. Counters step through a sequence of states: the ripple (asynchronous) counter clocks each flip-flop with the previous output and accumulates delay, the synchronous counter uses one clock for all flip-flops and is faster, with EN and CO for cascading.Shift Registers and Counters →.

Quiz 14

A non-programmable digital system is divided into a datapath and a control unit. The control unit:

  • a. fetches instructions from a memory using a program counter
  • b. is a purely combinational network with no state
  • c. determines the microoperations only from its own inputs and from the status signals of the datapath
Show the result

c.

Show the full solution

In a non-programmable system the control unit executes no instructions: it is a state machine with fixed logic that, from the input signals and the status signals coming from the datapath (for instance a counter reaching zero), produces the control signals that trigger the microoperations. Choice a describes the control unit of a programmable system such as a CPU. Choice b is false: it needs states (for instance ready, acc, init) to remember the phase of the operation. Theory: Datapath and Control UnitA register cell is a flip-flop with logic for microoperations, shared across the n cells of a register. In a programmable system (CPU) the control unit executes instructions fetched from memory using a program counter; in a non-programmable system the control unit decides the microoperations only from inputs and datapath status signals. Complete example: summing five values with start, res and busy; the datapath has ACC_REG, OUT_REG and CNT_REG (decrementer, MUX, status signal zero); microoperations are combinations of control signals; the control unit is a 3-state Mealy machine (ready, acc, init).Datapath and Control Unit →, Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →.

Quiz 15

A register AA implements the logic microoperations A←A∧BA\leftarrow A\wedge B, A←A⊕BA\leftarrow A\oplus B and A←A∨BA\leftarrow A\vee B, enabled by the control signals ANDAND, EXOREXOR and OROR (at most one is 11; if all are 00 the register holds). With EXOR=1EXOR=1 and the other two signals at 00, the input of the flip-flop of bit ii is:

  • a. Di=Ai⊕BiD_i=A_i\oplus B_i
  • b. Di=Ai+BiD_i=A_i+B_i
  • c. Di=Ai BiD_i=A_i\,B_i
Show the result

a.

Show the full solution

The equation of the register cell is Di=Ai‾Bi C1+AiBi‾ C2+AiBi C3D_i=\overline{A_i}B_i\,C_1+A_i\overline{B_i}\,C_2+A_iB_i\,C_3 with C1=EXOR+ORC_1=EXOR+OR, C2=EXOR+OR+HC_2=EXOR+OR+H, C3=AND+OR+HC_3=AND+OR+H, where HH is the hold condition. With EXOR=1EXOR=1, AND=OR=0AND=OR=0 and H=0H=0: C1=1C_1=1, C2=1C_2=1, C3=0C_3=0, so Di=Ai‾Bi+AiBi‾=Ai⊕BiD_i=\overline{A_i}B_i+A_i\overline{B_i}=A_i\oplus B_i. Choice c is the case AND=1AND=1 and choice b the case OR=1OR=1. Theory: Datapath and Control UnitA register cell is a flip-flop with logic for microoperations, shared across the n cells of a register. In a programmable system (CPU) the control unit executes instructions fetched from memory using a program counter; in a non-programmable system the control unit decides the microoperations only from inputs and datapath status signals. Complete example: summing five values with start, res and busy; the datapath has ACC_REG, OUT_REG and CNT_REG (decrementer, MUX, status signal zero); microoperations are combinations of control signals; the control unit is a 3-state Mealy machine (ready, acc, init).Datapath and Control Unit →.

Quiz 16

In the system that sums five values (control unit with states ready, acc, init; the counter is initialised to 55), the signal start is asserted for one clock cycle while the system is in ready. For how many clock cycles, counting the cycle in which start is 11, is busy equal to 11?

  • a. 55
  • b. 77
  • c. 66
Show the result

b.

Show the full solution

busy is 11 in the cycle with start=1 (state ready, first value accumulated, counter 5→45\to4): 11 cycle. Then the machine is in acc with the counter at 4,3,2,14,3,2,1 (four more values accumulated) and finally at 00, when zero=1 and the sum is copied to the output: 55 cycles in acc. Last, init clears the accumulator and reloads the counter: 11 cycle. Total 1+5+1=71+5+1=7 cycles; then the machine is back in ready and busy=0. Choice a counts only the acc cycles. Theory: Datapath and Control UnitA register cell is a flip-flop with logic for microoperations, shared across the n cells of a register. In a programmable system (CPU) the control unit executes instructions fetched from memory using a program counter; in a non-programmable system the control unit decides the microoperations only from inputs and datapath status signals. Complete example: summing five values with start, res and busy; the datapath has ACC_REG, OUT_REG and CNT_REG (decrementer, MUX, status signal zero); microoperations are combinations of control signals; the control unit is a 3-state Mealy machine (ready, acc, init).Datapath and Control Unit →.

Quiz 17

In an instruction BRZ (branch if the tested register is zero) located at address 9090, the 6-bit offset field is 110010110010, interpreted in two's complement, and the target address is PC+offsetPC+\text{offset} with PCPC the address of the instruction. If the register is zero, the next instruction is at address:

  • a. 7676
  • b. 140140
  • c. 104104
Show the result

a.

Show the full solution

The 6-bit offset 1100102110010_2 has the sign bit equal to 11: it is negative. In two's complement 1100102=50−64=−14110010_2=50-64=-14. The target is 90+(−14)=7690+(-14)=76 (branch backwards). Choice b reads the offset as unsigned (90+50=14090+50=140); choice c uses +14+14, the magnitude without the sign. If the register were not zero the next address would be 9191. Theory: Machine Instructions, Addressing Modes, RISC and CISCA machine instruction is a fixed-width word split into an opcode and operand fields; in a load/store architecture only load and store reach memory, and operands are given by a few addressing modes (register, register indirect, immediate, PC-relative). RISC machines use simple fixed-length instructions that fit one pass through the pipeline, 32 registers with R0 equal to 0 and four addressing modes; CISC machines have complex variable-length instructions, many addressing modes and a microprogrammed control (a ROM-based state machine) taking several cycles.Machine Instructions, Addressing Modes, RISC and CISC →, Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle ControlThe 16-bit instruction word has an opcode of 7 bits plus register fields (DR, SA, SB or an immediate OP) or a branch format with a 6-bit PC-relative signed offset; the instruction set is load/store with ADD, SUB, logic, shifts, LDI, ADI, LD, ST, BRZ, BRN and JMP. In the single-cycle computer (separate instruction and data memories) a combinational instruction decoder derives MB, MD, RW, MW, PL, JB, BC from bits 15, 14, 13 and 9 and FS from bits 12 to 9, and the clock period is the sum of the delays on the critical path (9.8 ns in the example). In the multi-cycle computer (one memory) an instruction register, internal registers R8 to R15 and a sequential decoder are needed: fetch (INF) plus one or more execution states.Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle Control →.

Quiz 18

A load/store processor executes LD R3,(R5) with register-indirect addressing. The register R5R5 contains 4040, the memory location at address 4040 contains 77 and the memory location at address 77 contains 1212. After the instruction R3R3 contains:

  • a. 4040
  • b. 1212
  • c. 77
Show the result

c.

Show the full solution

Quiz 19

A system has 1616-bit virtual addresses and 44 KB pages, so the page number is made of the 44 high bits and the offset of the 1212 low bits. The page table maps virtual page 22 to physical frame 99 (valid). The virtual address 0x2A5C is translated into the physical address:

  • a. 0x2A5C
  • b. 0x9A5C
  • c. 0xA25C
Show the result

b.

Show the full solution

Quiz 20

In a virtual memory system a page that is a candidate for replacement has valid bit 11 and dirty bit 11. This means that:

  • a. it must be written back to the disk before its frame is reused
  • b. it can be overwritten immediately, because the disk already holds an identical copy
  • c. a page fault has occurred
Show the result

a.

Show the full solution

The dirty bit is set when at least one write occurred in the page since it was loaded: the copy in main memory is more recent than the one on the disk, which would be lost if the frame were reused. The operating system must therefore save the page to the disk first. With dirty bit 00 the page could be discarded (choice b). A page fault (choice c) happens when the valid bit is 00, i.e. the requested page is not in memory and must be fetched from the disk. Theory: Virtual Memory and PagingVirtual memory shows every program the whole size of main memory plus disk, with the same addresses usable by all programs without interference; dedicated hardware translates virtual to physical addresses page by page using a page table whose rows carry valid, dirty and used bits. The offset is unchanged by the translation. The TLB caches recent translations to avoid extra memory accesses, and a page fault (valid bit 0) means the page must be fetched from disk.Virtual Memory and Paging →, 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 circuit receives a decimal digit in BCD on the variables A,B,C,DA,B,C,D (AA most significant bit, DD least significant bit; the combinations 10101010 to 11111111 never occur) and drives the top-left segment ff of a seven-segment display. The segments are named as in the figure: aa top, bb top right, cc bottom right, dd bottom, ee bottom left, ff top left, gg middle. The digits are drawn as follows: 0=abcdef0=abcdef, 1=bc1=bc, 2=abdeg2=abdeg, 3=abcdg3=abcdg, 4=bcfg4=bcfg, 5=acdfg5=acdfg, 6=acdefg6=acdefg, 7=abc7=abc, 8=abcdefg8=abcdefg, 9=abcdfg9=abcdfg. The output FF must be 11 when segment ff has to be lit and 00 otherwise.

  1. Write the truth table of FF and the Karnaugh map, marking the don't-care conditions.
  2. Find the minimal product-of-sums (POS) expression of FF, showing the groups of zeros used on the map, and say which groups are essential.
  3. Find the minimal sum-of-products (SOP) expression and compare the two forms (number of terms and of literals). What would the POS be if the don't-care conditions were not used?
  4. Draw the circuit that implements the POS with NOR gates only (inverters allowed for the complemented inputs) and count gates, gate inputs and CMOS transistors. Compare with the NAND-NAND realisation of the SOP.
  5. What do the POS and the SOP circuits output for the unused input combinations 10101010 to 11111111? Does it matter?
Show the result
  1. F=1F=1 for the digits 0,4,5,6,8,90,4,5,6,8,9; F=0F=0 for 1,2,3,71,2,3,7; don't care for 1010 to 1515.
  2. F=(B+C‾)(C‾+D‾)(A+B+D‾)F=(B+\overline C)(\overline C+\overline D)(A+B+\overline D), three essential groups of zeros: {2,3,10,11}\{2,3,10,11\}, {3,7,11,15}\{3,7,11,15\}, {1,3}\{1,3\}. Without don't cares: F=(B+C‾)(A‾+B‾)(C‾+D‾)(A+B+D‾)F=(B+\overline C)(\overline A+\overline B)(\overline C+\overline D)(A+B+\overline D).
  3. F=A+BC‾+B D‾+C‾ D‾F=A+B\overline C+B\,\overline D+\overline C\,\overline D (44 products, 77 literals); the POS has 33 sums and 77 literals.
  4. F=B+C‾‾+C‾+D‾‾+A+B+D‾‾‾F=\overline{\overline{B+\overline C}+\overline{\overline C+\overline D}+\overline{A+B+\overline D}}: two 2-input NORs, one 3-input NOR, one 3-input NOR at the output, two inverters: 66 gates, 1010 gate inputs plus 22 inverters, 2424 transistors. The NAND-NAND of the SOP uses 33 inverters, three 2-input NANDs and one 4-input NAND: 2626 transistors.
  5. POS circuit on 10,…,1510,\dots,15: 0,0,1,1,1,00,0,1,1,1,0; SOP circuit: 1,1,1,1,1,11,1,1,1,1,1. They differ on 10,11,1510,11,15, which does not matter because those inputs never occur.
Show the full solution

Point 1: truth table and map. For every digit one looks at whether the drawing contains segment ff (top-left): it is lit in 0,4,5,6,8,90,4,5,6,8,9 and off in 1,2,3,71,2,3,7 (the 77 is drawn with three segments only, as stated). The rows 1010 to 1515 are not BCD digits and become don't care (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 →).

digit ABCDABCD FF digit ABCDABCD FF
0 0000 1 8 1000 1
1 0001 0 9 1001 1
2 0010 0 10 1010 X
3 0011 0 11 1011 X
4 0100 1 12 1100 X
5 0101 1 13 1101 X
6 0110 1 14 1110 X
7 0111 0 15 1111 X

Karnaugh map (rows ABAB, columns CDCD in Gray order; the cell index is the digit):

AB\CDAB\backslash CD 00 01 11 10
00 1 (0) 0 (1) 0 (3) 0 (2)
01 1 (4) 1 (5) 0 (7) 1 (6)
11 X (12) X (13) X (15) X (14)
10 1 (8) 1 (9) X (11) X (10)

Point 2: minimal POS. For a POS one groups the zeros (the cells 1,2,3,71,2,3,7), using the don't cares as zeros where this enlarges the groups, and then complements each group with De Morgan (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 →, 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 →). Groups of zeros:

  • {2,3,10,11}\{2,3,10,11\}: AA varies, B=0B=0, C=1C=1; the product for F‾\overline F is B‾ C\overline B\,C, the sum is B+C‾B+\overline C. It is essential: it is the only large group that contains cell 22.
  • {3,7,11,15}\{3,7,11,15\} (the column CD=11CD=11): C=1,D=1C=1,D=1, the sum is C‾+D‾\overline C+\overline D. Essential: it is the only large group containing cell 77.
  • {1,3}\{1,3\}: A=0,B=0,D=1A=0,B=0,D=1, the sum is A+B+D‾A+B+\overline D. Essential: cell 11 has no larger group (its neighbours 00, 55, 99 are ones, which cannot be in a group of zeros).

In a sum, a variable is direct if it is 00 in the group and negated if it is 11 (reversed with respect to the SOP). Therefore F=(B+C‾)(C‾+D‾)(A+B+D‾).F=(B+\overline C)(\overline C+\overline D)(A+B+\overline D). Check: the digit 5=01015=0101 gives (1+1)(1+0)(0+1+0)=1(1+1)(1+0)(0+1+0)=1; the digit 7=01117=0111 gives (1+0)(0+0)(…)=0(1+0)(0+0)(\ldots)=0 because C‾+D‾=0\overline C+\overline D=0; the digit 2=00102=0010 gives (0+0)=0(0+0)=0. A script enumerated the sixteen inputs and confirmed that the formula is correct on all valid digits. If the don't cares were not used (the rows 1010 to 1515 taken as F=0F=0), those six cells would become zeros that must be covered: the group {12,13,14,15}\{12,13,14,15\} (ABAB, sum A‾+B‾\overline A+\overline B) is needed in addition, while the other three groups stay the same ({2,3,10,11}\{2,3,10,11\} and {3,7,11,15}\{3,7,11,15\} are now made of true zeros). The minimal POS (confirmed with sympy) is F=(B+C‾)(A‾+B‾)(C‾+D‾)(A+B+D‾),F=(B+\overline C)(\overline A+\overline B)(\overline C+\overline D)(A+B+\overline D), with 44 sums and 99 literals: using the don't cares saves one sum and two literals. Typical mistake: forgetting to use the don't cares, or making a group only of don't cares.

Point 3: minimal SOP and comparison. Grouping the ones 0,4,5,6,8,90,4,5,6,8,9 and the don't cares: AA (the whole lower half {8,…,15}\{8,\dots,15\}), C‾ D‾\overline C\,\overline D (cells 0,4,8,120,4,8,12), B C‾B\,\overline C (cells 4,5,12,134,5,12,13), B D‾B\,\overline D (cells 4,6,12,144,6,12,14). All four are essential (cell 99 only by AA, cell 00 only by C‾ D‾\overline C\,\overline D, cell 55 only by BC‾B\overline C, cell 66 only by BD‾B\overline D): F=A+B C‾+B D‾+C‾ D‾.F=A+B\,\overline C+B\,\overline D+\overline C\,\overline D . SOP: 44 products and 1+2+2+2=71+2+2+2=7 literals; POS: 33 sums and 2+2+3=72+2+3=7 literals. Same literals, but the POS has one term less. Gate-input cost: POS 2+2+3+3=102+2+3+3=10 (three OR gates and one AND), SOP 2+2+2+4=102+2+2+4=10 (three AND gates and one OR; AA enters directly): equal.

Point 4: NOR-NOR. A POS maps directly on NOR-NOR (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 →): F=S1S2S3=S1‾+S2‾+S3‾‾F=S_1S_2S_3=\overline{\overline{S_1}+\overline{S_2}+\overline{S_3}} with each Si‾\overline{S_i} produced by a NOR. Here F=  B+C‾‾  +  C‾+D‾‾  +  A+B+D‾‾  ‾.F=\overline{\;\overline{B+\overline C}\;+\;\overline{\overline C+\overline D}\;+\;\overline{A+B+\overline D}\;}. Gates: NOR2(B,C‾)\text{NOR}_2(B,\overline C), NOR2(C‾,D‾)\text{NOR}_2(\overline C,\overline D), NOR3(A,B,D‾)\text{NOR}_3(A,B,\overline D), final NOR3\text{NOR}_3, plus two inverters for C‾\overline C and D‾\overline D (shared by the sums). Six gates, 2+2+3+3=102+2+3+3=10 gate inputs and two inverters. Transistors (a gate with nn inputs has 2n2n transistors, CMOS Gates and Technology ParametersIn CMOS integrated circuits MOSFETs are modelled as switches: nMOS closed when the gate is 1, pMOS closed when the gate is 0. A static gate has a pull-up network (only pMOS, to Vdd) and a dual pull-down network (only nMOS, to ground): one is ON and the other OFF. NAND has series nMOS and parallel pMOS, NOR the opposite; an n-input gate has 2n transistors. Real-gate parameters: fan-in, fan-out, noise margin, propagation delay, power dissipation and cost.CMOS Gates and Technology Parameters →): 4+4+6+6+2⋅2=244+4+6+6+2\cdot2=24. The SOP on NAND-NAND is F=A‾⋅BC‾‾⋅BD‾‾⋅C‾ D‾‾‾F=\overline{\overline A\cdot\overline{B\overline C}\cdot\overline{B\overline D}\cdot\overline{\overline C\,\overline D}}: three 2-input NANDs (1212 transistors), one 4-input NAND (88), and three inverters for A‾\overline A, C‾\overline C, D‾\overline D (66): 2626 transistors. The NOR-NOR form is slightly cheaper (one inverter less); both have fan-in at most 44. A script checked on all 1616 inputs that the two circuits equal the POS and the SOP, respectively.

Point 5: unused combinations. Evaluating the POS on 10,…,1510,\dots,15 (1010,1011,1100,1101,1110,11111010,1011,1100,1101,1110,1111): 1010 and 1111 have B=0,C=1B=0,C=1, so B+C‾=0B+\overline C=0 and F=0F=0; 12,1312,13 and 1414 give 11; 1515 has C‾+D‾=0\overline C+\overline D=0, so F=0F=0. The result is 0,0,1,1,1,00,0,1,1,1,0. The SOP contains AA and gives 11 on all six. The two circuits are not equal as Boolean functions but they are equal on the valid inputs, which is all that is required: the don't cares were exactly the freedom to choose these values. Typical mistake: claiming that the two minimal forms must coincide.


Exercise 2 (points 10)

A synchronous counter is made of three positive-edge-triggered D flip-flops with outputs Q2Q1Q0Q_2Q_1Q_0 (Q2Q_2 most significant bit; the state number is the value of Q2Q1Q0Q_2Q_1Q_0 in binary). It has an input ENEN and an output zz. When EN=1EN=1, at each rising edge of the clock the counter goes through the cyclic sequence of states 0→2→3→5→6→0→⋯0\to2\to3\to5\to6\to0\to\cdots and when EN=0EN=0 it holds its state. The output is z=1z=1 only when the counter is in state 66 (Moore output). A reset brings the counter to state 00.

  1. Write the state table for EN=1EN=1 and identify the unused states. How many flip-flops are needed?
  2. Find the minimal expressions of the next-state functions N2,N1,N0N_2,N_1,N_0 (for EN=1EN=1) with Karnaugh maps, using the unused states as don't cares, and the expression of zz.
  3. Include the enable and write the equations of D2,D1,D0D_2,D_1,D_0.
  4. Check that the counter is self-starting: what happens if, after power-up, it is in one of the unused states?
  5. Starting from state 00, find the sequence of states and of zz for EN=1,1,0,1,1,1,0,1,1,1,1EN=1,1,0,1,1,1,0,1,1,1,1 (one value per clock cycle).
  6. With EN=1EN=1 and a clock at 100100 MHz, what are frequency and duty cycle of zz?
Show the result
  1. Five states: 000→010→011→101→110→000000\to010\to011\to101\to110\to000; unused states 001001, 100100, 111111; three flip-flops.
  2. N2=Q0N_2=Q_0, N1=Q1‾+Q2‾ Q0‾N_1=\overline{Q_1}+\overline{Q_2}\,\overline{Q_0}, N0=Q2‾ Q1N_0=\overline{Q_2}\,Q_1, z=Q2Q1z=Q_2Q_1.
  3. Di=EN⋅Ni+EN‾⋅QiD_i=EN\cdot N_i+\overline{EN}\cdot Q_i for i=0,1,2i=0,1,2 (a 2-to-1 multiplexer with select ENEN in front of each flip-flop).
  4. Yes: 001→110001\to110, 100→010100\to010, 111→100→010111\to100\to010; no loops among unused states; a valid state is reached in at most 22 clock cycles.
  5. Present states: 000,010,011,011,101,110,000,000,010,011,101000,010,011,011,101,110,000,000,010,011,101; z=0,0,0,0,0,1,0,0,0,0,0z=0,0,0,0,0,1,0,0,0,0,0 (the next state after the last cycle is 110110).
  6. fz=100/5=20f_z=100/5=20 MHz, duty cycle 1/5=20%1/5=20\%.
Show the full solution

Point 1: state table. Five states need ⌈log⁡25⌉=3\lceil\log_2 5\rceil=3 flip-flops (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 →); the encoding is given by the state number. With three bits there are 88 combinations: 33 are unused. For EN=1EN=1:

present state Q2Q1Q0Q_2Q_1Q_0 next state N2N1N0N_2N_1N_0 zz
0 000 2 010 0
2 010 3 011 0
3 011 5 101 0
5 101 6 110 0
6 110 0 000 1
1 001 unused X X
4 100 unused X X
7 111 unused X X

Since the counter must hold when EN=0EN=0, the design is split: first the next state for EN=1EN=1 (33 variables, easy maps), then the enable (Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →).

Point 2: Karnaugh maps. The next state of a D flip-flop is its input (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 →). Maps with rows Q2Q_2 and columns Q1Q0Q_1Q_0 in Gray order (the number in brackets is the state):

N2N_2 (ones in states 33 and 55):

Q2\Q1Q0Q_2\backslash Q_1Q_0 00 01 11 10
0 0 (0) X (1) 1 (3) 0 (2)
1 X (4) 1 (5) X (7) 0 (6)

The column Q0=1Q_0=1 (1,3,5,71,3,5,7: two ones and two don't cares) gives N2=Q0N_2=Q_0.

N1N_1 (ones in 0,2,50,2,5):

Q2\Q1Q0Q_2\backslash Q_1Q_0 00 01 11 10
0 1 (0) X (1) 0 (3) 1 (2)
1 X (4) 1 (5) X (7) 0 (6)

Groups: {0,1,4,5}\{0,1,4,5\} (the don't cares 1,41,4 are used as ones): Q1‾\overline{Q_1}; {0,2}\{0,2\}: Q2‾ Q0‾\overline{Q_2}\,\overline{Q_0}. So N1=Q1‾+Q2‾ Q0‾N_1=\overline{Q_1}+\overline{Q_2}\,\overline{Q_0}.

N0N_0 (ones in 2,32,3):

Q2\Q1Q0Q_2\backslash Q_1Q_0 00 01 11 10
0 0 (0) X (1) 1 (3) 1 (2)
1 X (4) 0 (5) X (7) 0 (6)

One group {2,3}\{2,3\}: N0=Q2‾ Q1N_0=\overline{Q_2}\,Q_1. (The cell 77 cannot be used: the group {2,3,6,7}\{2,3,6,7\} would contain the zero in cell 66.)

Output: z=1z=1 in state 6=1106=110 and don't care in 111111 (unused): the group {6,7}\{6,7\} gives z=Q2Q1z=Q_2Q_1 (also z=Q2Q0‾z=Q_2\overline{Q_0} would be minimal, using the unused state 44 instead of 77). The equations were checked by a script: for EN=1EN=1 they reproduce the cycle 0→2→3→5→6→00\to2\to3\to5\to6\to0. Typical mistakes: treating the unused states as zeros (more complex equations), or using the don't cares in a group made only of don't cares.

Point 3: enable. With the load enable technique the register input is chosen by a 2-to-1 multiplexer: EN=1EN=1 loads the new state, EN=0EN=0 feeds back the flip-flop output (Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →): Di=EN⋅Ni+EN‾⋅Qi,i=0,1,2,D_i=EN\cdot N_i+\overline{EN}\cdot Q_i,\quad i=0,1,2, that is D2=EN Q0+EN‾ Q2D_2=EN\,Q_0+\overline{EN}\,Q_2, D1=EN (Q1‾+Q2‾ Q0‾)+EN‾ Q1D_1=EN\,(\overline{Q_1}+\overline{Q_2}\,\overline{Q_0})+\overline{EN}\,Q_1, D0=EN Q2‾ Q1+EN‾ Q0D_0=EN\,\overline{Q_2}\,Q_1+\overline{EN}\,Q_0. With EN=0EN=0 every state, valid or unused, is held. (Clock gating on ENEN would be a worse alternative, because of the clock skew.)

Point 4: self-start. At power-up the flip-flops can be in any of the 88 combinations; if the equations send an unused state into a loop of unused states the counter is stuck. Evaluating the equations (EN=1EN=1):

  • 001001 (Q2=0,Q1=0,Q0=1Q_2=0,Q_1=0,Q_0=1): N2=1N_2=1, N1=Q1‾=1N_1=\overline{Q_1}=1, N0=0N_0=0, so the next state is 110110 (state 66, valid);
  • 100100: N2=0N_2=0, N1=1N_1=1, N0=0N_0=0, next state 010010 (state 22, valid);
  • 111111: N2=Q0=1N_2=Q_0=1, N1=Q1‾+Q2‾ Q0‾=0+0=0N_1=\overline{Q_1}+\overline{Q_2}\,\overline{Q_0}=0+0=0, N0=Q2‾ Q1=0N_0=\overline{Q_2}\,Q_1=0, next state 100100 (unused), then 010010. No unused state leads to another loop: after at most two clock edges the counter is in the valid cycle (7→4→27\to4\to2). This is the point of the check: with a different use of the don't cares the result could be a lock-up and a reset would be needed. Note that in state 77 the output is z=1z=1 once, a harmless glitch after an abnormal start.

Point 5: sequence. The output is Moore: it is read in the present state. For each cycle (present state, ENEN, next state):

cycle 1 2 3 4 5 6 7 8 9 10 11
present state 000 010 011 011 101 110 000 000 010 011 101
ENEN 1 1 0 1 1 1 0 1 1 1 1
next state 010 011 011 101 110 000 000 010 011 101 110
zz 0 0 0 0 0 1 0 0 0 0 0

The cycles with EN=0EN=0 (3 and 7) do not advance the count. The counter has returned to state 00 after five advances (cycles 1, 2, 4, 5, 6): modulo 55.

Point 6: frequency of zz. With EN=1EN=1 the sequence has period 55 clock cycles and z=1z=1 in one of them: fz=fclk/5=100/5=20f_z=f_{clk}/5=100/5=20 MHz and duty cycle 1/5=20%1/5=20\%. The circuit is a divider by 55 with a narrow output pulse (Shift Registers and CountersA shift register is a chain of D flip-flops, each output feeding the next input, so bits move one position per clock edge; it has serial input and output, optional parallel load (Shift has priority over Load) and a bidirectional version with a 4-to-1 MUX per stage (S1S0: 00 hold, 01 shift left, 10 shift right, 11 load). Uses: serial/parallel conversion, serial interfaces, delay lines, pseudo-random generators. Counters step through a sequence of states: the ripple (asynchronous) counter clocks each flip-flop with the previous output and accumulates delay, the synchronous counter uses one clock for all flip-flops and is faster, with EN and CO for cascading.Shift Registers and Counters →). Typical mistake: dividing by 88, the number of combinations of three bits, instead of the number of states in the sequence.


Exercise 3 (points 10)

Describe in VHDL the counter of Exercise 2: inputs clk, rst, en, outputs q (3 bits, the state Q2Q1Q0Q_2Q_1Q_0) and z. With en='1' the state goes through 0,2,3,5,6,0,…0,2,3,5,6,0,\dots at each rising edge of clk, with en='0' it holds; z is '1' only in state 66. The reset rst is asynchronous, active high, and brings the state to 00. Separate the memory element from the combinational parts in the code.

  1. Write the VHDL code (entity and architecture).
  2. Write a test bench that makes the counter go through all the states, tests the hold with en='0' and the asynchronous reset.
  3. Report the expected states and output at the rising edges of the test bench.
  4. The circuit of Exercise 2 is built with these delays (ns): flip-flop tpdt_{pd} 0.450.45 maximum and 0.300.30 minimum, ts=0.25t_s=0.25, th=0.12t_h=0.12; inverter 0.08/0.040.08/0.04; AND2 0.20/0.120.20/0.12; OR2 0.22/0.140.22/0.14; NAND2 0.15/0.090.15/0.09; multiplexer 2-to-1: data →\to output 0.30/0.180.30/0.18, select →\to output 0.40/0.220.40/0.22 (maximum/minimum). The next-state logic is: N2=Q0N_2=Q_0 (wire), N1=Q1 (Q2+Q0)‾N_1=\overline{Q_1\,(Q_2+Q_0)} (an OR2 followed by a NAND2), N0=Q2‾ Q1N_0=\overline{Q_2}\,Q_1 (an inverter and an AND2); a multiplexer in front of every flip-flop implements the enable; en comes from a flip-flop of the same clock. Find the critical path, the minimum clock period and the maximum frequency, check the hold constraint and say whether the circuit works at 800800 MHz.
Show the result
  1. Three processes: state register with asynchronous reset (state <= "000" when rst='1', state <= next_state on the rising edge), next-state process with case and if en='0', output z <= '1' when state = "110".
  2. A test bench with a clock process and an input process: reset, en='1' for 77 cycles, en='0' for 22 cycles, en='1' for 22 cycles, then a reset pulse in the middle of a clock phase.
  3. States after the rising edges at 50,70,90,110,130,150,17050,70,90,110,130,150,170 ns: 010,011,101,110,000,010,011010,011,101,110,000,010,011 (with z=1z=1 after 110110 ns); hold at 011011 at 190190 and 210210 ns; 101101 at 230230 ns, 110110 at 250250 ns; the reset pulse at 265265 ns brings the state to 000000 immediately (no edge).
  4. Critical path Q2Q_2 or Q0→Q_0\to OR2 →\to NAND2 →\to MUX data: tCOMB=0.22+0.15+0.30=0.67t_{COMB}=0.22+0.15+0.30=0.67 ns; Tmin=0.45+0.67+0.25=1.37T_{min}=0.45+0.67+0.25=1.37 ns; fmax≈730f_{max}\approx730 MHz. Hold: 0.30+0.18=0.48≥0.120.30+0.18=0.48\ge0.12, slack 0.360.36 ns. At 800800 MHz (T=1.25T=1.25 ns) the setup is violated by 0.120.12 ns: no.
Show the full solution

Point 1: code. The three-process scheme of an FSM (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 →): process 1 is the state register, with the asynchronous reset tested first and rst in the sensitivity list (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 →); process 2 computes the next state combinationally from state and en; the output is a concurrent assignment (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 →).

vhdl
library IEEE;
use IEEE.std_logic_1164.all;

entity cnt5 is
  port ( clk, rst, en : in  std_logic;
         q            : out std_logic_vector(2 downto 0);
         z            : out std_logic );
end cnt5;

architecture beh of cnt5 is
  signal state, next_state : std_logic_vector(2 downto 0);
begin
  -- process 1: state register (3 D flip-flops), asynchronous reset active high
  reg : process (clk, rst)
  begin
    if rst = '1' then
      state <= "000";
    elsif clk'event and clk = '1' then
      state <= next_state;
    end if;
  end process;

  -- process 2: next state, purely combinational; every branch assigns next_state
  nxt : process (state, en)
  begin
    if en = '0' then
      next_state <= state;                -- hold
    else
      case state is
        when "000"  => next_state <= "010";
        when "010"  => next_state <= "011";
        when "011"  => next_state <= "101";
        when "101"  => next_state <= "110";
        when "110"  => next_state <= "000";
        when others => next_state <= "000";  -- unused states: restart
      end case;
    end if;
  end process;

  -- outputs: Moore, they depend only on the state
  q <= state;
  z <= '1' when state = "110" else '0';
end beh;

Remarks. (i) en is in the list of the process nxt, together with state: if en were missing the simulation would ignore its changes. (ii) Every branch assigns next_state (when others\texttt{when others} and the else of the if), so no latch is inferred. (iii) The when others branch is required because std_logic_vector has many more values than the 55 used; here the unused states restart from 000000, a choice stronger than the one obtained from the minimised equations of Exercise 2 (where 111111 goes first to 100100): both are self-starting and equal on the valid sequence. (iv) In the VHDL zz is exactly state = "110", whereas the minimised circuit has z=Q2Q1z=Q_2Q_1 which is also 11 in the unused state 111111: again a difference only outside the valid cycle. The code could not be compiled in the preparation of this mock and was checked by hand against the transition table of Exercise 2 and by a program that simulates the same table.

Point 2: test bench. A clock process and an input process, with the inputs changed on the falling edge, away from the active edge (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 →, 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 →). The clock starts at 00: rising edges at 10,30,50,…10,30,50,\dots ns, falling edges at 20,40,…20,40,\dots ns.

vhdl
library IEEE;
use IEEE.std_logic_1164.all;

entity tb_cnt5 is
end tb_cnt5;

architecture test of tb_cnt5 is
  signal clk, rst, en, z : std_logic;
  signal q : std_logic_vector(2 downto 0);
  constant PERIOD : time := 20 ns;
begin
  dut : entity work.cnt5(beh) port map (clk, rst, en, q, z);

  gen_clock : process
  begin
    clk <= '0'; wait for PERIOD/2;
    clk <= '1'; wait for PERIOD/2;
  end process;

  apply_inputs : process
  begin
    rst <= '1'; en <= '0';
    wait for 2*PERIOD;               -- reset until 40 ns (falling edge)
    rst <= '0'; en <= '1';
    wait for 7*PERIOD;               -- 7 rising edges with en = 1: 50 ... 170 ns
    en <= '0';                       -- at 180 ns: hold for the edges at 190 and 210 ns
    wait for 2*PERIOD;
    en <= '1';                       -- at 220 ns: two more steps (230, 250 ns)
    wait for 2*PERIOD;
    wait for PERIOD/4;               -- 265 ns: clock low, no edge
    rst <= '1';                      -- asynchronous reset: the state must change at once
    wait for 3*PERIOD/4;
    rst <= '0';                      -- at 280 ns (falling edge): counting restarts at 290 ns
    wait for 3*PERIOD;
    std.env.stop;
  end process;
end test;

The sequence passes through all five states and through the five arcs with en='1'; the hold (en=0en=0) is shown in state 33 only; the unused states cannot be reached from the test bench, because the state is internal.

Point 3: expected result. The state is shown after each rising edge (Moore: z changes together with the state):

time (ns) rst en state after the edge z what is tested
10, 30 1 0 000 0 reset
50 0 1 010 0 arc 0→20\to2
70 0 1 011 0 arc 2→32\to3
90 0 1 101 0 arc 3→53\to5
110 0 1 110 1 arc 5→65\to6, z=1z=1
130 0 1 000 0 arc 6→06\to0
150, 170 0 1 010, 011 0 second round
190, 210 0 0 011, 011 0 hold
230, 250 0 1 101, 110 0, 1 counting resumes
265 (no edge) 1 1 000 0 asynchronous reset
270 1 1 000 0 reset has priority over the clock
290, 310, 330 0 1 010, 011, 101 0 restart after reset

The key observation is the line at 265265 ns: the state and z return to 00 before any clock edge, which would not happen with a synchronous reset (the state would change only at 270270 ns). A script that simulates the transition table with these stimuli reproduced this table. Typical mistakes: changing the inputs on the rising edge (a race with the clock), forgetting the initial reset (the state is undefined 'U' and never recovers), never testing en='0'.

Point 4: timing analysis. The constraint is T≥tpd,FF+tCOMB+ts,FFT\ge t_{pd,FF}+t_{COMB}+t_{s,FF} with the maximum delays (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 →). Delays of the paths from a flip-flop output to a flip-flop input (everything ends in the data input of a multiplexer, 0.300.30 ns):

  • Q0→D2Q_0\to D_2: wire and multiplexer, 0.300.30 ns; hold path Qi→Q_i\to multiplexer: 0.300.30 ns;
  • Q1→Q_1\to NAND2 →\to MUX (D1)(D_1): 0.15+0.30=0.450.15+0.30=0.45 ns;
  • Q2Q_2 or Q0→Q_0\to OR2 →\to NAND2 →\to MUX (D1)(D_1): 0.22+0.15+0.30=0.670.22+0.15+0.30=\mathbf{0.67} ns;
  • Q1→Q_1\to AND2 →\to MUX (D0)(D_0): 0.20+0.30=0.500.20+0.30=0.50 ns; Q2→Q_2\to inverter →\to AND2 →\to MUX (D0)(D_0): 0.08+0.20+0.30=0.580.08+0.20+0.30=0.58 ns;
  • en→en\to select of the MUX: 0.400.40 ns.

The critical path is the one through the OR2 and the NAND2: tCOMB=0.67t_{COMB}=0.67 ns, so Tmin=0.45+0.67+0.25=1.37 ns,fmax=11.37 ns≈730 MHz.T_{min}=0.45+0.67+0.25=1.37\ \text{ns},\qquad f_{max}=\frac1{1.37\ \text{ns}}\approx 730\ \text{MHz}. (Check of the logic: Q1(Q2+Q0)‾=Q1‾+Q2‾ Q0‾=N1\overline{Q_1(Q_2+Q_0)}=\overline{Q_1}+\overline{Q_2}\,\overline{Q_0}=N_1.)

Hold. With the minimum delays the shortest path is a flip-flop output straight into a multiplexer data input (0.180.18 ns); the select path takes 0.220.22 ns and all the others more. tpd,min⁡+tCOMB,min⁡=0.30+0.18=0.48≥th=0.12t_{pd,\min}+t_{COMB,\min}=0.30+0.18=0.48\ge t_h=0.12: the constraint is satisfied with a slack of 0.48−0.12=0.360.48-0.12=0.36 ns. Hold does not depend on the clock frequency.

800800 MHz. T=1/800 MHz=1.25T=1/800\ \text{MHz}=1.25 ns <1.37<1.37 ns: the setup is violated by 1.37−1.25=0.121.37-1.25=0.12 ns (slack −0.12-0.12 ns) and the circuit does not work. It can be cured by lowering the frequency (at 700700 MHz, T=1.43T=1.43 ns, the slack is +0.059+0.059 ns; any frequency up to 730730 MHz works) or by shortening the critical path (for instance with a faster gate for N1N_1). Typical mistakes: taking the select path of the multiplexer as the critical one only because the select delay is larger than the data delay; forgetting tpd,FFt_{pd,FF} and tst_s; using the minimum delays for the setup check or the maximum delays for the hold check.


Self-assessment grid
exercise points what must be there for full points typical mistakes
Quiz 1-20 20 one answer per question; each wrong answer costs 0.30.3, so leave blank when really unsure Gray conversion in the wrong direction, parity "correcting" errors, P∝VddP\propto V_{dd} instead of Vdd2V_{dd}^2, offset of the branch read as unsigned, offset translated in the page address
Ex. 1, points 1-2 5 truth table and map with don't cares; three groups of zeros; F=(B+C‾)(C‾+D‾)(A+B+D‾)F=(B+\overline C)(\overline C+\overline D)(A+B+\overline D) with correct signs wrong sign of the literals in the sums, don't cares ignored, groups not maximal
Ex. 1, point 3 1.5 minimal SOP with four products; comparison in terms of terms and literals; POS without don't cares has 4 sums SOP from zeros, wrong count of literals
Ex. 1, points 4-5 3.5 NOR-NOR circuit with inverters, gate and transistor count (2n2n per gate); outputs 0,0,1,1,1,00,0,1,1,1,0 on the unused inputs NAND instead of NOR for a POS, forgetting inverters, saying the circuits must coincide on all inputs
Ex. 2, points 1-3 5 state table with three unused states; N2,N1,N0N_2,N_1,N_0 and zz minimal; DiD_i with the enable unused states as zeros, enable put on the clock, Di=NiD_i=N_i without the hold
Ex. 2, points 4-6 5 self-start check for 001001, 100100, 111111; sequence of states and zz read in the present state; 2020 MHz and 20%20\% not checking the unused states, reading zz in the next state, dividing by 88
Ex. 3, points 1-2 4 three-process VHDL, reset asynchronous and first in the process, en in the list, no latch; test bench with clock, reset, hold and asynchronous reset rst inside the edge branch, missing else or when others, inputs on the rising edge
Ex. 3, point 3 2 table of states and z at each rising edge; reset visible at 265265 ns with no edge not noticing that the asynchronous reset acts before the edge
Ex. 3, point 4 4 critical path 0.670.67 ns, Tmin=1.37T_{min}=1.37 ns, fmax≈730f_{max}\approx730 MHz; hold slack 0.360.36 ns; 800800 MHz fails by 0.120.12 ns with the remedies missing tpdt_{pd} or tst_s, minimum delays in the setup check, "lower the frequency" proposed for a hold violation