1
0
Fork 0
2023-fpga-computer/src/sap2/top.v

181 lines
2.3 KiB
Coq
Raw Permalink Normal View History

2023-01-15 21:57:23 +00:00
module top(
input CLK
);
reg[15:0] bus;
always @(*) begin
if (a_en) begin
bus = a_out;
end else if (b_en) begin
bus = b_out;
end else if (c_en) begin
bus = c_out;
end else if (alu_en) begin
bus = alu_out;
end else if (pc_en) begin
bus = pc_out;
end else if (mdr_en) begin
bus = mem_out;
end else begin
bus = 16'b0;
end
end
wire rst;
2023-01-15 21:57:23 +00:00
wire hlt;
wire clk;
clock clock(
.hlt(hlt),
.clk_in(CLK),
.clk_out(clk)
);
wire pc_inc;
wire pc_load;
wire pc_en;
wire[15:0] pc_out;
2023-01-15 21:57:23 +00:00
pc pc(
.clk(clk),
.rst(rst),
2023-01-15 21:57:23 +00:00
.inc(pc_inc),
.load(pc_load),
.bus(bus),
.out(pc_out)
2023-01-15 21:57:23 +00:00
);
wire ir_load;
wire[7:0] ir_out;
2023-01-15 21:57:23 +00:00
ir ir(
.clk(clk),
.rst(rst),
2023-01-15 21:57:23 +00:00
.load(ir_load),
.bus(bus),
.out(ir_out)
2023-01-15 21:57:23 +00:00
);
wire mar_loadh;
wire mar_loadl;
wire mdr_load;
wire mdr_en;
wire ram_load;
wire ram_enh;
wire ram_enl;
wire call;
wire ret;
wire[15:0] mem_out;
2023-01-15 21:57:23 +00:00
memory mem(
.clk(clk),
.rst(rst),
2023-01-15 21:57:23 +00:00
.mar_loadh(mar_loadh),
.mar_loadl(mar_loadl),
.mdr_load(mdr_load),
.ram_load(ram_load),
.ram_enh(ram_enh),
.ram_enl(ram_enl),
.call(call),
.ret(ret),
.bus(bus),
.out(mem_out)
2023-01-15 21:57:23 +00:00
);
wire a_load;
wire a_en;
wire a_inc;
wire a_dec;
wire[7:0] a_out;
2023-01-15 21:57:23 +00:00
register reg_a(
.clk(clk),
.rst(rst),
2023-01-15 21:57:23 +00:00
.load(a_load),
.inc(a_inc),
.dec(a_dec),
.bus(bus),
.out(a_out)
2023-01-15 21:57:23 +00:00
);
wire b_load;
wire b_en;
wire b_inc;
wire b_dec;
wire[7:0] b_out;
2023-01-15 21:57:23 +00:00
register reg_b(
.clk(clk),
.rst(rst),
2023-01-15 21:57:23 +00:00
.load(b_load),
.inc(b_inc),
.dec(b_dec),
.bus(bus),
.out(b_out)
2023-01-15 21:57:23 +00:00
);
wire c_load;
wire c_en;
wire c_inc;
wire c_dec;
wire[7:0] c_out;
2023-01-15 21:57:23 +00:00
register reg_c(
.clk(clk),
.rst(rst),
2023-01-15 21:57:23 +00:00
.load(c_load),
.inc(c_inc),
.dec(c_dec),
.bus(bus),
.out(c_out)
2023-01-15 21:57:23 +00:00
);
wire[2:0] alu_op;
wire alu_load;
wire alu_en;
wire[7:0] alu_out;
2023-01-15 21:57:23 +00:00
alu alu(
.clk(clk),
.rst(rst),
.a(a_out),
2023-01-15 21:57:23 +00:00
.load(alu_load),
.op(alu_op),
.bus(bus),
.out(alu_out)
2023-01-15 21:57:23 +00:00
);
wire[1:0] flags_out;
2023-01-15 21:57:23 +00:00
wire flags_lda;
wire flags_ldb;
wire flags_ldc;
flags flags(
.clk(clk),
.rst(rst),
.a(a_out),
.b(b_out),
.c(c_out),
2023-01-15 21:57:23 +00:00
.load_a(flags_lda),
.load_b(flags_ldb),
.load_c(flags_ldc),
.out(flags_out)
2023-01-15 21:57:23 +00:00
);
controller controller(
.clk(clk),
.rst(rst),
.opcode(ir_out),
.flags(flags_out),
.out({
2023-01-15 21:57:23 +00:00
hlt,
a_load, a_en, a_inc, a_dec,
b_load, b_en, b_inc, b_dec,
c_load, c_en, c_inc, c_dec,
flags_lda, flags_ldb, flags_ldc,
alu_op, alu_load, alu_en,
2023-01-15 21:57:23 +00:00
ir_load,
pc_inc, pc_load, pc_en,
mar_loadh, mar_loadl, mdr_load,
2023-01-15 21:57:23 +00:00
mdr_en,
ram_load, ram_enh, ram_enl,
call, ret})
2023-01-15 21:57:23 +00:00
);
endmodule