0
0
Verilogprogramming~10 mins

Register (multi-bit flip-flop) in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a 4-bit register named 'reg_out'.

Verilog
reg [1] reg_out;
Drag options to blanks, or click blank then click option'
Awire
Binput
Coutput
D[3:0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'wire' instead of 'reg' for a register.
Not specifying the bit width with brackets.
2fill in blank
medium

Complete the always block sensitivity list to trigger on the positive edge of clock 'clk'.

Verilog
always @([1] clk) begin
  // register logic
end
Drag options to blanks, or click blank then click option'
Anegedge
Blevel
Cposedge
Dedge
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'negedge' instead of 'posedge' when positive edge is required.
Omitting 'posedge' or 'negedge' keyword.
3fill in blank
hard

Fix the error in the register assignment inside the always block.

Verilog
always @(posedge clk) begin
  reg_out [1] data_in;
end
Drag options to blanks, or click blank then click option'
A!=
B<=
C==
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using blocking assignment '=' inside clocked always blocks.
Using comparison operators '==' or '!=' instead of assignment.
4fill in blank
hard

Fill both blanks to complete the reset logic for the register (active high synchronous reset).

Verilog
always @(posedge clk) begin
  if ([1]) begin
    reg_out [2] 4'b0000;
  end else begin
    reg_out <= data_in;
  end
end
Drag options to blanks, or click blank then click option'
Areset
Bclk
C<=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using blocking assignment '=' inside the always block for registers.
Checking the wrong signal in the if condition.
5fill in blank
hard

Fill all three blanks to complete a parameterized register module with width 'WIDTH'.

Verilog
module register #(parameter WIDTH = [1]) (
  input wire clk,
  input wire reset,
  input wire [WIDTH-1:0] data_in,
  output reg [WIDTH-1:0] reg_out
);

always @(posedge clk) begin
  if (reset) begin
    reg_out [2] [3]'b0;
  end else begin
    reg_out <= data_in;
  end
end

endmodule
Drag options to blanks, or click blank then click option'
A8
B<=
CWIDTH
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using blocking assignment '=' inside the always block.
Not using the parameter WIDTH for the reset value width.