always @(posedge tclk or posedge reset) begin if (reset) begin pc<=0; ir<=0; end else begin if(select[4]) begin if(~select[8] & ~select[7]) pc<=pc+12'b1; if(~select[8] & select[7]) pc<=ir[11:0]; if(select[8] & ~select[7]) pc<=as; if(select[8] & select[7]) pc<=12'hf00; end else if(select[9]) as<=pc; else if(select[3]) ir<=d_bus; end end assign a_bus=(select[0]) ? pc: ir[11:0]; assign halt=(ir==12'hfff);
always @(posedge tclk or posedge reset) begin if (reset) begin acc<=0; latch<=0; c<=0; z<=0; end else begin if(select[5]) begin casex(ir[15:12]) 4'b0000: begin {c,latch}<=acc + d_bus; z<=((acc + d_bus)==16'h0000); end 4'b0001: begin {c,latch}<=acc - d_bus; z<=((acc - d_bus)==16'h0000); end 4'b0010: begin {c,latch}<=~(acc & d_bus); z<=(~(acc & d_bus)==16'h0000); end 4'b0011: begin {c,latch}<=acc << 1; z<=((acc <<1 )==16'h0000); end 4'b1110: begin sacc<=acc; sc<=c; sz<=z; end 4'b1111: begin acc<=sacc; c<=sc; z<=sz; end default: latch<=acc; endcase end if(select[6]) acc<=d_bus; end end assign d_bus= (select[1]) ? latch: 16'bz; endmodule
// details of select signals // select9: AS latch // select8: Return from sub-routine or interrupt // select7: PC count-up or PC load (jump) // select6: ACC latch // select5: ALU latch // select4: PC count up or load enable // select3: IR latch // select2: memory read(0)/write(1) // select1: ACC data select from ALU or memory // select0: address select PC(1) or IR_L(0)
always @(posedge sclk or posedge reset) begin if (reset) begin ss<=3'b000; i<=0; end else case (ss) 3'b000: if(ipt & ~i) begin select<=10'b1000000000; ss<=3'b100; i<=1; end // interupt 1: as<-pc else begin select<=10'b0000001001; ss<=3'b001; end // fetch cycle 1
3'b001: begin select<=10'b0000010000; ss<=3'b010; end // fetch cycle 2 3'b010: casex (ir[15:12]) // exec cycle 1 4'b0XXX: begin select<=10'b0000100000; ss<=3'b011; end // alu operation 1 4'b1000: begin select<=10'b0001000000; ss<=3'b000; end // LD 4'b1001: begin select<=10'b0000100000; ss<=3'b011; end // ST 4'b1010: begin if(~c) begin select<=10'b0000000000; ss<=3'b000; end // JPC: c=0, nop if(c) begin select<=10'b0010010000; ss<=3'b000; end // JPC: c=1, jump end 4'b1011: begin if(~z) begin select<=10'b0010010000; ss<=3'b000; end // JPNZ: z=0, jump if(z) begin select<=10'b0000000000; ss<=3'b000; end // JPNZ: z=1, nop end 4'b1100: begin select<=10'b1000000000; ss<=3'b011; end // CALL 1 4'b1101: begin select<=10'b0100010000; ss<=3'b000; i<=0; end // RET 4'b1110: begin select<=10'b0000100000; ss<=3'b000; end // PUSH 4'b1111: begin select<=10'b0001100000; ss<=3'b000; end // PULL endcase 3'b011: casex (ir[15:12]) // exec cycle 2 4'b0XXX: begin select<=10'b0001000010; ss<=3'b000; end // alu operation 2 4'b1001: begin select<=10'b0000000110; ss<=3'b000; end // ST 2 4'b1100: begin select<=10'b0010010000; ss<=3'b000; end // CALL 2 endcase 3'b100: begin select<=10'b0110010000; ss<=3'b000; end // interupt 2: pc<-F000H endcase end