Prev Problem
Next Problem

16. Parking Lot Status

module parking_status16 (
    input  [15:0] slots,
    output        all_full,
    output        any_free
);
    // all_full is 1 only when every slot bit is 1
    assign all_full = &slots;

    // any_free is 1 if at least one slot bit is 0
    // Two equivalent forms; pick one:
    assign any_free = ~(&slots);     // invert the reduction-AND
    // assign any_free = |(~slots);  // reduction-OR of inverted bits
endmodule

💡Remember

  • Reduction AND &slots collapses 16 bits to 1: true iff all are 1.
  • Any free slot can be checked as ~(&slots) or |(~slots) (both equivalent).
  • Four-state caveat: if any slots bit is x/z in simulation, &slots can be x, making outputs x or unknown—initialize or avoid multiple drivers when testing.
  • Use sized, readable literals for tests (e.g., 16'hFFFF, 16'hAAAA).