Add: basic element for risc-v single cycle cpu
This commit is contained in:
23
rtl/alu.v
23
rtl/alu.v
@@ -1,6 +1,19 @@
|
||||
module alu (S, A, B);
|
||||
output [31:0] S;
|
||||
input [31:0] A, B;
|
||||
module alu (input [31:0] input_a, input_b,
|
||||
input [2:0] op_code,
|
||||
output reg [31:0] out);
|
||||
|
||||
always@ (*) begin
|
||||
case (op_code)
|
||||
3'b000 : out <= input_a + input_b;
|
||||
3'b001 : out <= input_a << input_b;
|
||||
3'b010 : out <= (input_a < input_b) ? 1 : 0;
|
||||
3'b011 : out <= input_a ^ input_b;
|
||||
3'b100 : out <= input_a >> input_b;
|
||||
3'b101 : out <= input_a >>> input_b;
|
||||
3'b110 : out <= input_a | input_b;
|
||||
3'b111 : out <= input_a & input_b;
|
||||
default : out <= 32'b0;
|
||||
endcase
|
||||
end
|
||||
|
||||
xor N[31:0] (S, A, B);
|
||||
endmodule
|
||||
endmodule
|
||||
|
||||
19
rtl/decoder.v
Normal file
19
rtl/decoder.v
Normal file
@@ -0,0 +1,19 @@
|
||||
module decoder (input [31:0] instruction,
|
||||
output immediate,
|
||||
output we_reg, adder_pc,
|
||||
output [1:0] input_reg,
|
||||
output [4:0] select_a, select_b, select_d,
|
||||
output source_alu,
|
||||
output [2:0] op_code_alu,
|
||||
output mem_we,
|
||||
output [31:0] mem_address
|
||||
output jmp_pc, b_pc);
|
||||
|
||||
always @(*) begin
|
||||
if (reset == 1)
|
||||
registers[0] <= 32'b0;
|
||||
else if (we == 1)
|
||||
registers[select_d] <= input_d;
|
||||
end
|
||||
|
||||
endmodule
|
||||
8
rtl/instruction.v
Normal file
8
rtl/instruction.v
Normal file
@@ -0,0 +1,8 @@
|
||||
module instruction (input [31:0] address,
|
||||
output [31:0] instruction);
|
||||
|
||||
reg [63:0] memory [31:0];
|
||||
|
||||
assign instruction = memory[address];
|
||||
|
||||
endmodule
|
||||
18
rtl/memory.v
Normal file
18
rtl/memory.v
Normal file
@@ -0,0 +1,18 @@
|
||||
module instruction (input clock, reset,
|
||||
input we,
|
||||
input [31:0] address,
|
||||
input [31:0] data_in
|
||||
output [31:0] data_out);
|
||||
|
||||
reg [63:0] memory [31:0];
|
||||
|
||||
always @(posedge clock, reset) begin
|
||||
if (reset == 1)
|
||||
memory[0] <= 32'b0;
|
||||
else if (we == 1)
|
||||
memory[address] <= data_in;
|
||||
end
|
||||
|
||||
assign data_out = memory[address];
|
||||
|
||||
endmodule
|
||||
7
rtl/mux2_1.v
Normal file
7
rtl/mux2_1.v
Normal file
@@ -0,0 +1,7 @@
|
||||
module mux2_1 (input [31:0] A, B,
|
||||
input S,
|
||||
output [31:0] O);
|
||||
|
||||
assign O = S ? B : A;
|
||||
|
||||
endmodule
|
||||
8
rtl/mux4_1.v
Normal file
8
rtl/mux4_1.v
Normal file
@@ -0,0 +1,8 @@
|
||||
module mux4_1 (input [31:0] A, B, C, D,
|
||||
input [1:0] S,
|
||||
output [31:0] O);
|
||||
|
||||
assign O = S[0] ? (S[1] ? D : C)
|
||||
: (S[1] ? B : A);
|
||||
|
||||
endmodule
|
||||
12
rtl/program_counter.v
Normal file
12
rtl/program_counter.v
Normal file
@@ -0,0 +1,12 @@
|
||||
module program_counter (input clock, reset,
|
||||
input [31:0] new_pc,
|
||||
output reg [31:0] pc);
|
||||
|
||||
always @ (posedge clock, reset) begin
|
||||
if (reset == 1)
|
||||
pc <= 32'b0;
|
||||
else
|
||||
pc <= new_pc;
|
||||
end
|
||||
|
||||
endmodule
|
||||
18
rtl/registers_bank.v
Normal file
18
rtl/registers_bank.v
Normal file
@@ -0,0 +1,18 @@
|
||||
module registers_bank (input clock, reset, we,
|
||||
input [4:0] select_d, select_a, select_b,
|
||||
input [31:0] input_d,
|
||||
output [31:0] output_a, output_b);
|
||||
|
||||
reg [31:0] registers[31:0];
|
||||
|
||||
always @(posedge clock, reset) begin
|
||||
if (reset == 1)
|
||||
registers[0] <= 32'b0;
|
||||
else if (we == 1)
|
||||
registers[select_d] <= input_d;
|
||||
end
|
||||
|
||||
assign output_a = registers[select_a];
|
||||
assign output_b = registers[select_b];
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user