Shift Register

Task description


In this tutorial you will be shown how to model a 4-bit shift register (with capability of shifting to right) in SystemC , once in a behavioural way and the other time using structural design (by using D flip-flops). The structural design of a 4-bit shift register composed of four D-FFs is shown in Figure 1. Such design requires a serial input which is shifter at every clock cycle. we will use this example to understand how to design shift register properly in SystemC.


Shift Register
Figure 1. 4-bit shift register (with shift to right capability)

For this lab, first we focus on the behavioural design of the shift register. Thus, you will need the following set of codes:
  1. sr.h : Behavioural description of a 4-bit shift register
  2. sr.cpp : Behavioural description of a 4-bit shift register
  3. shift_register_tb.cpp : Test-bench for the 4-bit shift register

Tasks

  1. Download the shift register files, read sr.h and sr.cpp, and simulate them using the provided testbench shift_register_tb.cpp.
  2. Compile your code with the following comamnd (you might need to change the path to your library):
    g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux64 -Wl,-rpath=$SYSTEMC_HOME/lib-linux64 -o shift_register shift_register_tb.cpp -lsystemc -lm .
  3. If everything is done correctly, the circuit should shift a bit with the value of logic "one" to the right at each positive edge of the clock signal. The generated VCD file should also generate a waveform like the one shown in Figure 2 in GTKWave.


  4. Figure 2. Waveforms for 4-bit shift register in GTKWave
  1. Now we want to make a sturctural version of the same 4-bit shift register using D-FFs. For this purpose, you can download the files dff.h and dff.cpp and include in your project. Redesign the sr.cpp and sr.h files so that the design would conform to the one shown in Figure 1. Then use this test-bench shift_register_tb.cpp to verify your design. Store it in the same folder as the other design files.
  2. Compile your code with the following comamnd (you might need to change the path to your library):
    g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux64 -Wl,-rpath=$SYSTEMC_HOME/lib-linux64 -o shift_register shift_register_tb.cpp -lsystemc -lm .
  3. If everything is done correctly, the circuit should shift a bit with the value of logic "one" to the right at each positive edge of the clock signal. The generated VCD file should generate a waveform like the one shown in Figure 2 in GTKWave.