BitFlow

SR Latch

intermediate · sequential · 100 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

SR Latch The SR (Set-Reset) latch is the most fundamental memory element. It is **level-sensitive** — the output changes whenever S or R changes while the enable is active (or immediately for an unclocked latch). Implement an **active-high SR latch** (no clock, no enable): - S=1, R=0 → Q=1, Qn=0 (Set) - S=0, R=1 → Q=0, Qn=1 (Reset) - S=0, R=0 → Q holds previous state (memory) - S=1, R=1 → **Forbidden** (undefined/invalid — both outputs forced to 0) **Interface** | Port | Direction | Description | |------|-----------|---------------------| | `s` | input | Set (active-high) | | `r` | input | Reset (active-high)| | `q` | output | State output | | `qn` | output | Complement output | **Implementation note:** Use cross-coupled NOR gates (structural style) or a behavioural `always @(*)` with if-else. For synthesis, avoid the S=R=1 case.

Constraints

  • Implement with always @(*) behavioural style.
  • When S=1, R=1: assign q=0, qn=0 (treat as forbidden).
  • When S=0, R=0: q and qn must hold (use reg).

Examples

Input: s=1, r=0

Output: q=1, qn=0

Set

Input: s=0, r=1

Output: q=0, qn=1

Reset

Input: s=0, r=0

Output: q=prev, qn=prev_n

Hold

Common questions

What does the SR Latch problem ask you to build?
SR Latch The SR (Set-Reset) latch is the most fundamental memory element. It is **level-sensitive** — the output changes whenever S or R changes while the enable is active (or immediately for an unclocked latch).
What constraints does SR Latch have?
Implement with always @(*) behavioural style.; When S=1, R=1: assign q=0, qn=0 (treat as forbidden).; When S=0, R=0: q and qn must hold (use reg).
What is an example input and output for SR Latch?
Input s=1, r=0 gives output q=1, qn=0. Set
Which Verilog concepts does SR Latch practise?
sequential, latch, level-sensitive, SR.