always @(posedge gclk or posedge reset) begin if (reset) sclk <= 1'b0; else sclk <= ~sclk; end always @(negedge gclk or posedge reset) begin if (reset) tclk <= 1'b0; else tclk <= ~tclk; end endmodule
always @(posedge tclk or posedge reset) begin if (reset) begin pc<=5'b0; ir<=8'b0; end else begin if(select[7]) pc<=ir[4:0]; else if(select[4]) pc<=pc+5'b1; else if(select[3]) ir<=d_bus; end end assign a_bus = (select[0])? pc: ir[4:0]; assign halt = (ir==8'hff);
always @(posedge tclk or posedge reset) begin if (reset) begin acc<=8'b0; latch<=8'b0; c<=1'b0; z<=1'b0; end else begin if(select[5]) begin 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 end if(select[6]) acc<=d_bus; end end assign d_bus= (select[1])? latch: 8'bz;
// Control signal // select[7]: PC load // select[6]: ACC latch // select[5]: ALU, c,z latch // select[4]: PC count up or load enable // select[3]: IR latch // select[2]: memory read/write // select[1]: ACC data from ALU:1 or memory:0 // select[0]: address select PC:1 or IR_L:0
always @(posedge sclk or posedge reset) begin if (reset) ss<=2'b00; else case (ss) 2'b00: begin select<=8'b00001001; ss<=2'b01; end // fetch cycle 1 2'b01: begin select<=8'b00010000; ss<=2'b10; end // fetch cycle 2 2'b10: // exec cycle 1 casex (ir[7:5]) 3'b0XX: begin select<=8'b00100000; ss<=2'b11; end // ADD,SUB,NAND,SHIFT 3'b100: begin select<=8'b01000000; ss<=2'b00; end // LD 3'b101: begin select<=8'b00100000; ss<=2'b11; end // ST 3'b110: begin // JPC if(~c) begin select<=8'b00000000; ss<=2'b00; end // C=0, nop if(c) begin select<=8'b10000000; ss<=2'b00; end // C=1, jump end 3'b111: begin // JPNZ if(~z) begin select<=8'b10000000; ss<=2'b00; end // Z=0, jump if(z) begin select<=8'b00000000; ss<=2'b00; end // z=1, nop end endcase 2'b11: // exec cycle 2 casex (ir[7:5]) 3'b0XX: begin select<=8'b01000010; ss<=2'b00; end // ADD,SUB,NAND,SHIFT 3'b101: begin select<=8'b00000110; ss<=2'b00; end // ST endcase endcase end