【正确答案】若Usg是并行数据: always @ (negedge Clk or negedge Rst) begin if(~rst) Asm <= 0; else if(Usg == 4’b1011) //注意,不能写成Usg = = 1011 Asm <= 1; end 若Usg是串行数据: reg [1:0]State; always @ (negedge Clk or negedge Rst) begin if(~rst) begin Asm <= 0; State <= 2'b0; end else case(State) 2'b00: if(Usg) State <= 2'b01; //检测到1 else State <= 2'b0; 2'b01: if(~Usg) State <= 2'b10; //检测到10 else State <= 2'b01; //若检测到11,状态回溯到检测到一个1 2'b10: if(Usg) State <= 2'b11; //检测到101 else State <= 2'b0; //若检测到100,状态回到初始状态 2'b11: if(Usg) begin State <= 2'b0; //成功 Asm<= 1; //检测到1011 end else State <= 2'b10; //检测到1010,状态回溯到检测到10 end default: ; endcase end