Bird
Raised Fist0
Verilogprogramming~5 mins

Wire type and continuous assignment in Verilog

Choose your learning style10 modes available
Introduction

Wire type is used to connect parts of a circuit. Continuous assignment lets you set a wire's value all the time, like a constant connection.

To connect outputs of one module to inputs of another.
To represent signals that change automatically based on other signals.
To create simple combinational logic without using always blocks.
To model physical wires in hardware that carry signals continuously.
Syntax
Verilog
wire wire_name;
assign wire_name = expression;

wire declares a wire signal.

assign sets the wire's value continuously based on the expression.

Examples
This creates a wire a that is always 1 (logic high).
Verilog
wire a;
assign a = 1'b1;
Wire b always has the same value as wire c.
Verilog
wire b, c;
assign b = c;
Wire out is the AND of in1 and in2.
Verilog
wire out;
assign out = in1 & in2;
Sample Program

This program defines a simple AND gate using a wire and continuous assignment. The testbench changes inputs and shows the output updating automatically.

Verilog
module simple_and(
  input wire in1,
  input wire in2,
  output wire out
);

assign out = in1 & in2;

endmodule

// Testbench
module test;
  reg a, b;
  wire c;

  simple_and uut(.in1(a), .in2(b), .out(c));

  initial begin
    a = 0; b = 0;
    #10 a = 0; b = 1;
    #10 a = 1; b = 0;
    #10 a = 1; b = 1;
    #10 $finish;
  end

  initial begin
    $monitor("At time %0t: a=%b b=%b => out=%b", $time, a, b, c);
  end
endmodule
OutputSuccess
Important Notes

Wires cannot store values; they reflect the value driven by continuous assignments or module outputs.

Use assign only with wires, not with reg types.

Continuous assignment updates the wire value immediately when inputs change.

Summary

Wire is for signals that connect parts of hardware.

Continuous assignment sets wire values all the time based on expressions.

This helps model real wires and simple logic in hardware design.

Practice

(1/5)
1. What is the main purpose of a wire type in Verilog?
easy
A. To represent a physical connection that continuously carries a signal
B. To store a value like a variable in software
C. To create a clock signal
D. To declare a constant value

Solution

  1. Step 1: Understand the role of wire in hardware

    A wire models a physical connection that carries signals continuously between components.
  2. Step 2: Compare with other types

    Unlike variables that store values, wire does not store but reflects the current driven value.
  3. Final Answer:

    To represent a physical connection that continuously carries a signal -> Option A
  4. Quick Check:

    Wire = continuous signal connection [OK]
Hint: Wire always models continuous signal flow [OK]
Common Mistakes:
  • Thinking wire stores values like variables
  • Confusing wire with registers
  • Assuming wire creates clocks
  • Believing wire declares constants
2. Which of the following is the correct syntax for a continuous assignment to a wire named out?
easy
A. wire out = a & b;
B. assign out = a & b;
C. out = a & b;
D. assign wire out = a & b;

Solution

  1. Step 1: Recall continuous assignment syntax

    Continuous assignments use the keyword assign followed by the wire name and expression.
  2. Step 2: Check each option

    assign out = a & b; correctly uses assign out = a & b;. Others misuse keywords or omit assign.
  3. Final Answer:

    assign out = a & b; -> Option B
  4. Quick Check:

    Continuous assignment = assign [OK]
Hint: Continuous assignment always starts with 'assign' [OK]
Common Mistakes:
  • Omitting 'assign' keyword
  • Trying to declare wire and assign in one line incorrectly
  • Using '=' without 'assign'
  • Writing 'assign wire' which is invalid
3. Given the code:
wire a = 1'b1;
wire b = 1'b0;
wire out;
assign out = a | b;

What is the value of out?
medium
A. 1'b1
B. 1'b0
C. High impedance (Z)
D. Unknown (X)

Solution

  1. Step 1: Evaluate the inputs

    Wire a is 1, b is 0.
  2. Step 2: Apply the OR operation

    OR of 1 and 0 is 1.
  3. Final Answer:

    1'b1 -> Option A
  4. Quick Check:

    1 OR 0 = 1 [OK]
Hint: OR with 1 always gives 1 [OK]
Common Mistakes:
  • Confusing OR with AND
  • Thinking output is unknown without clock
  • Assuming wire defaults to Z
  • Ignoring bit width notation
4. Identify the error in this Verilog snippet:
wire a;
assign a = 1'b1;
assign a = 1'b0;
medium
A. Wire cannot be assigned a constant value
B. Missing semicolon after wire declaration
C. Multiple continuous assignments to the same wire cause conflict
D. Wire must be declared as reg to assign values

Solution

  1. Step 1: Check continuous assignments

    Assigning two different values to the same wire causes conflict and is illegal.
  2. Step 2: Verify other options

    Wire can be assigned constants, semicolon is present, and wire does not need to be reg for continuous assignment.
  3. Final Answer:

    Multiple continuous assignments to the same wire cause conflict -> Option C
  4. Quick Check:

    One wire, one continuous assign [OK]
Hint: Only one continuous assign per wire allowed [OK]
Common Mistakes:
  • Trying to assign wire multiple times
  • Confusing wire with reg assignment rules
  • Missing semicolons (not in this case)
  • Thinking wire can't hold constants
5. You want to create a 4-bit wire sum that continuously adds two 4-bit wires a and b. Which code correctly uses wire and continuous assignment?
hard
A. wire [3:0] sum;\nassign sum = a & b;
B. reg [3:0] sum;\nalways @(*) sum = a + b;
C. wire sum;\nassign sum = a + b;
D. wire [3:0] sum;\nassign sum = a + b;

Solution

  1. Step 1: Check data types and widths

    Sum is 4-bit wire, matching the width of inputs a and b.
  2. Step 2: Verify continuous assignment for addition

    Using assign sum = a + b; continuously updates sum with the addition result.
  3. Step 3: Eliminate incorrect options

    reg [3:0] sum;\nalways @(*) sum = a + b; uses reg and always block (not wire). wire sum;\nassign sum = a + b; has wrong width for sum. wire [3:0] sum;\nassign sum = a & b; uses bitwise AND instead of addition.
  4. Final Answer:

    wire [3:0] sum; assign sum = a + b; -> Option D
  5. Quick Check:

    Wire + assign for continuous sum [OK]
Hint: Use wire with assign for continuous arithmetic [OK]
Common Mistakes:
  • Using reg instead of wire for continuous assign
  • Mismatching bit widths
  • Using bitwise AND instead of addition
  • Declaring wire without width for multi-bit signals
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard