Skip to question and answer

Hardware interview practice

SystemVerilog Interface Modports Explained

MediumVerification UtilitiesMultiple choice

Which modport declarations correctly describe a master that drives req and observes gnt, and a slave with the opposite roles?

Question code
interface bus_if; logic req, gnt; /* modports here */ endinterface

Answer choices

  1. A. modport master(input req, output gnt); modport slave(output req, input gnt);
  2. B. modport master(inout req, gnt); modport slave(inout req, gnt);
  3. C. modport master(output req, input gnt); modport slave(input req, output gnt);
  4. D. modport master(ref req, gnt); modport slave(ref req, gnt);

Concise answer

The answer and the key reason

Use `modport master(output req, input gnt);` and `modport slave(input req, output gnt);`. In each role declaration, `output` identifies what that endpoint produces and `input` identifies what it consumes.

Deeper explanation

Work through the implementation and tradeoffs

The requester originates `req`, making that signal an output in the master view and an input in the slave view. The responder originates `gnt`, so its directions are reversed. Declaring these complementary views lets the same interface instance expose a role-appropriate contract to each component. That is the intended producer-consumer relationship in this handshake.

A modport does not create another signal or insert logic; it controls how interface members are presented through a particular connection. Besides documenting the protocol, direction restrictions can catch accidental writes from a component that should only observe a signal. `inout` or `ref` would grant broader access than this handshake requires.

What to remember

  • Directions are endpoint-relative
  • Master drives `req`
  • Slave drives `gnt`

Practice the complete prompt

Explain it first, then compare the reviewed solution.

Open this exact question in the practice bank to attempt it, check your reasoning, and access the full member solution.Practice this question

Keep practicing

Verification UtilitiesWhy UVM Uses SystemVerilog Virtual InterfacesVerification UtilitiesSystemVerilog Clocking Blocks ExplainedUVM ComponentsHow to Pass a Virtual Interface with uvm_config_db