2023-01-15 21:57:23 +00:00
|
|
|
module top(
|
|
|
|
input CLK
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2023-02-17 03:25:05 +00:00
|
|
|
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;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[15:0] pc_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
pc pc(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
2023-01-15 21:57:23 +00:00
|
|
|
.inc(pc_inc),
|
|
|
|
.load(pc_load),
|
2023-02-17 03:25:05 +00:00
|
|
|
.bus(bus),
|
|
|
|
.out(pc_out)
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
wire ir_load;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[7:0] ir_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
ir ir(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
2023-01-15 21:57:23 +00:00
|
|
|
.load(ir_load),
|
|
|
|
.bus(bus),
|
2023-02-17 03:25:05 +00:00
|
|
|
.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;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[15:0] mem_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
memory mem(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.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),
|
2023-02-17 03:25:05 +00:00
|
|
|
.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;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[7:0] a_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
register reg_a(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
2023-01-15 21:57:23 +00:00
|
|
|
.load(a_load),
|
|
|
|
.inc(a_inc),
|
|
|
|
.dec(a_dec),
|
|
|
|
.bus(bus),
|
2023-02-17 03:25:05 +00:00
|
|
|
.out(a_out)
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
wire b_load;
|
|
|
|
wire b_en;
|
|
|
|
wire b_inc;
|
|
|
|
wire b_dec;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[7:0] b_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
register reg_b(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
2023-01-15 21:57:23 +00:00
|
|
|
.load(b_load),
|
|
|
|
.inc(b_inc),
|
|
|
|
.dec(b_dec),
|
|
|
|
.bus(bus),
|
2023-02-17 03:25:05 +00:00
|
|
|
.out(b_out)
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
wire c_load;
|
|
|
|
wire c_en;
|
|
|
|
wire c_inc;
|
|
|
|
wire c_dec;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[7:0] c_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
register reg_c(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
2023-01-15 21:57:23 +00:00
|
|
|
.load(c_load),
|
|
|
|
.inc(c_inc),
|
|
|
|
.dec(c_dec),
|
|
|
|
.bus(bus),
|
2023-02-17 03:25:05 +00:00
|
|
|
.out(c_out)
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
wire[2:0] alu_op;
|
|
|
|
wire alu_load;
|
|
|
|
wire alu_en;
|
2023-02-17 03:25:05 +00:00
|
|
|
wire[7:0] alu_out;
|
2023-01-15 21:57:23 +00:00
|
|
|
alu alu(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
|
|
|
.a(a_out),
|
2023-01-15 21:57:23 +00:00
|
|
|
.load(alu_load),
|
|
|
|
.op(alu_op),
|
2023-02-17 03:25:05 +00:00
|
|
|
.bus(bus),
|
|
|
|
.out(alu_out)
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
2023-02-17 03:25:05 +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),
|
2023-02-17 03:25:05 +00:00
|
|
|
.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),
|
2023-02-17 03:25:05 +00:00
|
|
|
.out(flags_out)
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
controller controller(
|
|
|
|
.clk(clk),
|
2023-02-17 03:25:05 +00:00
|
|
|
.rst(rst),
|
|
|
|
.opcode(ir_out),
|
|
|
|
.flags(flags_out),
|
|
|
|
.out({
|
2023-01-15 21:57:23 +00:00
|
|
|
hlt,
|
2023-02-17 03:25:05 +00:00
|
|
|
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,
|
2023-02-17 03:25:05 +00:00
|
|
|
pc_inc, pc_load, pc_en,
|
|
|
|
mar_loadh, mar_loadl, mdr_load,
|
2023-01-15 21:57:23 +00:00
|
|
|
mdr_en,
|
2023-02-17 03:25:05 +00:00
|
|
|
ram_load, ram_enh, ram_enl,
|
|
|
|
call, ret})
|
2023-01-15 21:57:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|