Spec: y indicates that the last two input samples (the current one and the one before) were both 1. The two codings differ in the state meaning and in the output expression.
Use the just-before-rising-edge observation point from the behavioral-difference waveform. The input has settled, but the state register has not yet accepted that sample. Both machines start in S0 after reset. The Mealy and Moore columns show state before / y before. Moore after is the state once the upcoming edge's update settles; its output then follows that new state.
Cycle | x | Mealy | Moore | Moore after |
|---|---|---|---|---|
0 | 0 | S0 / 0 | S0 / 0 | S0 |
1 | 0 | S0 / 0 | S0 / 0 | S0 |
2 | 1 | S0 / 0 | S0 / 0 | S1 |
3 | 1 | S1 / 1 | S1 / 0 | S11 |
4 | 0 | S1 / 0 | S11 / 1 | S0 |
5 | 1 | S0 / 0 | S0 / 0 | S1 |
6 | 1 | S1 / 1 | S1 / 0 | S11 |
7 | 1 | S1 / 1 | S11 / 1 | S11 |
8 | 0 | S1 / 0 | S11 / 1 | S0 |
9 | 0 | S0 / 0 | S0 / 0 | S0 |
10 | 0 | S0 / 0 | S0 / 0 | S0 |
11 | 0 | S0 / 0 | S0 / 0 | S0 |
At cycle 3, Mealy sees S1 together with x=1 and asserts y before the edge. Moore still occupies S1 and reports 0; that edge enters S11, so the following observation reports 1. Cycles 6 and 7 detect overlapping pairs, producing the two consecutive Moore hits at cycles 7 and 8. The one-cycle relationship is for this implementation and observation convention, not a universal latency rule for every Moore/Mealy design.
No. Before the cycle-4 edge, Moore still holds S11 from samples 2 and 3. Its y reports that earlier pair. The zero returns it to S0 at the upcoming edge; Mealy already sees the zero and reports no current pair.
Moore | Mealy | |
|---|---|---|
States |
|
|
Output |
|
|
Flops | 2 | 1 |
y = (state == S1) && x has two parts. The first (state == S1) is memory (“the previous sample was 1”), and the second (x) is the live input.
Remove && x and the output signals only “the previous sample was 1”, which is a different, wrong spec.
Moore: 3 states → 2 flip-flops. Mealy: 2 states → 1 flip-flop. The Moore machine needs a separate state to mean “two ones seen” so its output can depend on the state alone; the Mealy machine encodes that fact as “previous was 1 AND input is 1” at the output.
The listing below checks both machines against one reference model.
module det_moore (input logic clk, rst_n, x, output logic y);
typedef enum logic [1:0] {S0, S1, S11} state_t;
state_t state, next;
always_comb begin
next = state;
unique case (state)
S0: if (x) next = S1;
S1: if (x) next = S11; else next = S0;
S11: if (!x) next = S0;
default: next = S0;
endcase
end
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) state <= S0;
else state <= next;
assign y = (state == S11); // Moore: state only
endmodule
module det_mealy (input logic clk, rst_n, x, output logic y);
typedef enum logic {S0, S1} state_t; // S1 = the previous sample was 1
state_t state;
always_ff @(posedge clk or negedge rst_n)
if (!rst_n) state <= S0;
else if (x) state <= S1;
else state <= S0;
assign y = (state == S1) && x; // Mealy: state AND input
endmodule