top of page

Modports in SystemVerilog — Who Can Drive What?

1. Introduction

After interfaces, beginners usually feel confident and then suddenly hit this doubt:

If Alice and Bob share the same interface, how do we stop both from driving the same signal?

This is exactly why modports exist.

Interfaces group signals.
Modports control direction and responsibility.

2. What Is a Modport in System Verilog?

(Featured Snippet Target)

A modport in SystemVerilog defines how a module is allowed to access signals inside an interface by specifying signal directions and roles.

In simple words:

Modport = rules for using an interface

3. Alice & Bob Problem (Why Modports Exist)

Mental Picture (Memorize This)

  • Alice and Bob share one cable (interface)
     

  • Inside the cable are many wires
     

  • Alice should drive some wires
     

  • Bob should drive others
     

Without rules:

  • Both may drive the same wire
     

  • Bugs appear silently
     

Modports are those rules.

4. Interface Without Modport (Unsafe)

interface bus_if;

  logic [7:0] addr;

  logic [7:0] data;

  logic       valid;

  logic       ready;

endinterface

 

Problem:

  • Anyone can read or write anything
     

  • No protection
     

  • Easy to make mistakes

5. Interface With Modports (Safe and Clear)

Alice and Bob Agree on Roles

interface bus_if;

  logic [7:0] addr;

  logic [7:0] data;

  logic       valid;

  logic       ready;

 

  modport driver (

    output addr, data, valid,

    input  ready

  );

 

  modport dut (

    input  addr, data, valid,

    output ready

  );

endinterface

 

Now the rules are explicit.

6. Alice Uses driver Modport

module driver(bus_if.driver bus);

  initial begin

    bus.addr  = 8'h10;

    bus.data  = 8'hAA;

    bus.valid = 1'b1;

  end

endmodule

 

Alice:

  • Can drive addr, data, valid
     

  • Can only read ready
     

7. Bob Uses dut Modport

module dut(bus_if.dut bus);

  always_comb begin

    bus.ready = bus.valid;

  end

endmodule

 

Bob:

  • Can read inputs
     

Can only drive ready

8. Top-Level Connection (Still One Cable)

module top;

  bus_if bus();

 

  driver d1(bus);

  dut    d2(bus);

endmodule

 

Same interface.
Different permissions.

9. Why Modports Are Easy to Remember

Think of:

  • Interface → shared cable
     

  • Modport → access permission
     

Just like:

  • USB cable (interface)
     

Device roles (host vs device)

10. Interview Perspective (Short & Sharp)

Interviewers ask:

  • “Why modports?”
     

  • “What problem do they solve?”
     

Best One-Line Answer

Modports prevent incorrect signal driving by enforcing direction rules on interfaces.

11. One Sentence to Remember (Interview Gold)

Interface groups signals, modport controls who can touch what.

That’s all you need.

12. What’s Next

Now Alice and Bob:

  • Share signals
     

  • Have clear roles
     

Next question naturally is:

How do we make designs reusable and configurable?

👉 Next Article:
Parameters & localparam — Reusable Design

bottom of page