always @(negedge clk or posedge reset) begin if (reset) ss<=0; else case (ss) 3'b000: ss<=3'b001; 3'b001: begin if (ir[7:5]==3'b100) ss<=3'b101; // LD else if (ir[7:6]==2'b11) ss<=3'b110; // JPC, JPNZ else ss<=3'b010; // ADD,SUB,NAND,SHIFT, ST end 3'b010: if (ir[7:5]==3'b101) ss<=3'b100; // ST else ss<=3'b011; // ADD,SUB,NAND,SHIFT default: ss<=3'b000; // initial state endcase end
// pc, ir // always @(posedge clk or posedge reset) begin if (reset) begin pc<=0; ir<=0; end else begin if (ss==3'b000) ir<=d_bus; else if (ss==3'b001) pc<=pc+5'b1; else if(ss==3'b110) if ((ir[7:5]==3'b110 & c) | (ir[7:5]==3'b111 & ~z)) pc<=ir[4:0]; end end assign halt = (ir==8'hff); assign a_bus = (ss==3'b000)? pc: ir[4:0];
// alu, acc, latch // always @(posedge clk or posedge reset) begin if (reset) begin acc<=0; latch<=0; c<=0; z<=0; end else if(ss==3'b010) casex(ir[7:5]) 3'b000: begin {c,latch}<=acc + d_bus; z<=((acc + d_bus)==8'b0); end 3'b001: begin {c,latch}<=acc - d_bus; z<=((acc - d_bus)==8'b0); end 3'b010: begin {c,latch}<=~(acc & d_bus); z<=((~(acc & d_bus))==8'b0); end 3'b011: begin {c,latch}<=acc << 1; z<=((acc <<1 )==8'b0); end 3'b101: latch<=acc; endcase else if (ss==3'b011 | ss==3'b101) acc<=d_bus; end