Skip to content

Commit

Permalink
Skip NOP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ei9 committed Mar 7, 2021
1 parent c980cfe commit 3cc3028
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/sap1.v
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ endmodule // Adder and subtractor.
// end
// endmodule // Controller-Sequencer.

/*
// Version 2: Microprogramming.
module ctrl_seq (output[11:0] cb, output hlt, input clk,clr, input[3:0] i);
// Instructions
Expand Down Expand Up @@ -164,6 +165,74 @@ module ctrl_seq (output[11:0] cb, output hlt, input clk,clr, input[3:0] i);
cb = ctrl[counter];
end
endmodule // Controller-Sequencer.
*/

// Version 3: Skip nop.
module ctrl_seq (output[11:0] cb, output hlt, input clk,clr, input[3:0] i);
// Instructions
parameter LDA = 4'b0000;
parameter ADD = 4'b0001;
parameter SUB = 4'b0010;
parameter OUT = 4'b1110;
parameter HLT = 4'b1111;

reg[3:0] addr[0:15]; // Address ROM.
reg[11:0] ctrl[0:15]; // Control ROM.
reg[5:0] sc; // State counter.
reg[3:0] counter; // Counter.

assign hlt = i == HLT;
assign cb = ctrl[counter];

wire nop = cb == 12'h000;

always @ (negedge clk or posedge clr or posedge nop) begin
// Initialize address ROM.
addr[LDA] = 4'b0011;
addr[ADD] = 4'b0110;
addr[SUB] = 4'b1001;
addr[OUT] = 4'b1100;

// Initialize control ROM.
ctrl[0] = 12'h600; // 提取
ctrl[1] = 12'h800;
ctrl[2] = 12'h180;
ctrl[3] = 12'h240; // LDA
ctrl[4] = 12'h120;
ctrl[5] = 12'h000; // NOP
ctrl[6] = 12'h240; // ADD
ctrl[7] = 12'h102;
ctrl[8] = 12'h024;
ctrl[9] = 12'h240; // SUB
ctrl[10] = 12'h102;
ctrl[11] = 12'h02c;
ctrl[12] = 12'h011; // OUT
ctrl[13] = 12'h000; // NOP
ctrl[14] = 12'h000; // NOP

// State counter.
if (clr | nop) begin
sc = 6'b0;
end

if (!clk) begin
if(sc[2])
counter = addr[i]; // Load address in T3.
else
counter = counter + 1;

sc = sc << 1;
if (sc == 0) begin
sc = 6'b1;
end
end

if (clr | sc[0] | nop) begin
counter = 4'b0;
end
end
endmodule // Controller-Sequencer.


// control bus:
// 11 10 9 8 7 6 5 4 3 2 1 0
Expand Down

0 comments on commit 3cc3028

Please sign in to comment.