add verilog files for project one through five

This commit is contained in:
Konarak 2024-10-17 14:36:58 -04:00
parent b16bfcfd43
commit 792efa70cd
Signed by: konarak
GPG Key ID: DE5E99432B548849
37 changed files with 871 additions and 275 deletions

View File

@ -12,5 +12,8 @@ module And(
);
// Put your code here:
wire nand1;
Nand NAND1(a, b, nand1);
Nand NAND2(nand1, nand1, out);
endmodule

View File

@ -11,5 +11,20 @@ module And16(
);
// Put your code here:
And AND0(a[0], b[0], out[0]);
And AND1(a[1], b[1], out[1]);
And AND2(a[2], b[2], out[2]);
And AND3(a[3], b[3], out[3]);
And AND4(a[4], b[4], out[4]);
And AND5(a[5], b[5], out[5]);
And AND6(a[6], b[6], out[6]);
And AND7(a[7], b[7], out[7]);
And AND8(a[8], b[8], out[8]);
And AND9(a[9], b[9], out[9]);
And AND10(a[10], b[10], out[10]);
And AND11(a[11], b[11], out[11]);
And AND12(a[12], b[12], out[12]);
And AND13(a[13], b[13], out[13]);
And AND14(a[14], b[14], out[14]);
And AND15(a[15], b[15], out[15]);
endmodule

View File

@ -10,5 +10,5 @@ module Buffer(
);
// Put your code here:
assign out = in;
endmodule

View File

@ -10,5 +10,5 @@ module Buffer16(
);
// Put your code here:
assign out[15:0] = in[15:0];
endmodule

View File

@ -13,5 +13,9 @@ module DMux(
);
// Put your code here:
wire nsel;
Not NOT1(sel, nsel);
And AND1(in, sel, b);
And AND2(in, nsel, a);
endmodule

View File

@ -17,5 +17,11 @@ module DMux4Way(
);
// Put your code here:
wire outx;
wire outy;
DMux DMUXA(in, sel[1], outx, outy);
DMux DMUXB(outx, sel[0], a, b);
DMux DMUXC(outy, sel[0], c, d);
endmodule

View File

@ -21,5 +21,19 @@ module DMux8Way(
);
// Put your code here:
wire outi;
wire outj;
wire outw;
wire outx;
wire outy;
wire outz;
DMux DMUXA(in, sel[2], outi, outj);
DMux DMUXB(outi, sel[1], outw, outx);
DMux DMUXC(outj, sel[1], outy, outz);
DMux DMUXD(outw, sel[0], a, b);
DMux DMUXE(outx, sel[0], c, d);
DMux DMUXF(outy, sel[0], e, f);
DMux DMUXG(outz, sel[0], g, h);
endmodule

View File

@ -13,5 +13,12 @@ module Mux(
);
// Put your code here:
wire nsel;
wire outx;
wire outy;
Not NOT1(sel, nsel);
And AND1(b, sel, outx);
And AND2(a, nsel, outy);
Or OR(outx, outy, out);
endmodule

View File

@ -13,5 +13,20 @@ module Mux16(
);
// Put your code here:
Mux MUX0(a[0], b[0], sel, out[0]);
Mux MUX1(a[1], b[1], sel, out[1]);
Mux MUX2(a[2], b[2], sel, out[2]);
Mux MUX3(a[3], b[3], sel, out[3]);
Mux MUX4(a[4], b[4], sel, out[4]);
Mux MUX5(a[5], b[5], sel, out[5]);
Mux MUX6(a[6], b[6], sel, out[6]);
Mux MUX7(a[7], b[7], sel, out[7]);
Mux MUX8(a[8], b[8], sel, out[8]);
Mux MUX9(a[9], b[9], sel, out[9]);
Mux MUX10(a[10], b[10], sel, out[10]);
Mux MUX11(a[11], b[11], sel, out[11]);
Mux MUX12(a[12], b[12], sel, out[12]);
Mux MUX13(a[13], b[13], sel, out[13]);
Mux MUX14(a[14], b[14], sel, out[14]);
Mux MUX15(a[15], b[15], sel, out[15]);
endmodule

View File

@ -15,5 +15,10 @@ module Mux4Way16(
);
// Put your code here:
wire [15:0] outab;
wire [15:0] outcd;
Mux16 MUX16A(a[15:0], b[15:0], sel[0], outab[15:0]);
Mux16 MUX16B(c[15:0], d[15:0], sel[0], outcd[15:0]);
Mux16 MUX16(outab[15:0], outcd[15:0], sel[1], out[15:0]);
endmodule

View File

@ -19,5 +19,20 @@ module Mux8Way16(
);
// Put your code here:
wire [15:0] outab;
wire [15:0] outcd;
wire [15:0] outef;
wire [15:0] outgh;
wire [15:0] outabcd;
wire [15:0] outefgh;
Mux16 MUX16A(a[15:0], b[15:0], sel[0], outab[15:0]);
Mux16 MUX16B(c[15:0], d[15:0], sel[0], outcd[15:0]);
Mux16 MUX16C(e[15:0], f[15:0], sel[0], outef[15:0]);
Mux16 MUX16D(g[15:0], h[15:0], sel[0], outgh[15:0]);
Mux16 MUX16E(outab[15:0], outcd[15:0], sel[1], outabcd[15:0]);
Mux16 MUX16F(outef[15:0], outgh[15:0], sel[1], outefgh[15:0]);
Mux16 MUX16(outabcd[15:0], outefgh[15:0], sel[2], out[15:0]);
endmodule

View File

@ -10,5 +10,5 @@ module Not(
);
// Put your code here:
Nand NOT1(in, in, out);
endmodule

View File

@ -10,5 +10,20 @@ module Not16(
);
// Put your code here:
Not NOT0(in[0], out[0]);
Not NOT1(in[1], out[1]);
Not NOT2(in[2], out[2]);
Not NOT3(in[3], out[3]);
Not NOT4(in[4], out[4]);
Not NOT5(in[5], out[5]);
Not NOT6(in[6], out[6]);
Not NOT7(in[7], out[7]);
Not NOT8(in[8], out[8]);
Not NOT9(in[9], out[9]);
Not NOT10(in[10], out[10]);
Not NOT11(in[11], out[11]);
Not NOT12(in[12], out[12]);
Not NOT13(in[13], out[13]);
Not NOT14(in[14], out[14]);
Not NOT15(in[15], out[15]);
endmodule

View File

@ -12,5 +12,10 @@ module Or(
);
// Put your code here:
wire nanda;
wire nandb;
Nand NAND1(a, a, nanda);
Nand NAND2(b, b, nandb);
Nand NAND3(nanda, nandb, out);
endmodule

View File

@ -1,6 +1,6 @@
/**
* 16-bit bitwise And:
* for i = 0..15: out[i] = (a[i] and b[i])
* for i = 0: out[i] = (a[i] and b[i])
*/
`default_nettype none
@ -11,5 +11,20 @@ module Or16(
);
// Put your code here:
Or OR0(a[0], b[0], out[0]);
Or OR1(a[1], b[1], out[1]);
Or OR2(a[2], b[2], out[2]);
Or OR3(a[3], b[3], out[3]);
Or OR4(a[4], b[4], out[4]);
Or OR5(a[5], b[5], out[5]);
Or OR6(a[6], b[6], out[6]);
Or OR7(a[7], b[7], out[7]);
Or OR8(a[8], b[8], out[8]);
Or OR9(a[9], b[9], out[9]);
Or OR10(a[10], b[10], out[10]);
Or OR11(a[11], b[11], out[11]);
Or OR12(a[12], b[12], out[12]);
Or OR13(a[13], b[13], out[13]);
Or OR14(a[14], b[14], out[14]);
Or OR15(a[15], b[15], out[15]);
endmodule

View File

@ -10,5 +10,19 @@ module Or8Way(
);
// Put your code here:
wire outA;
wire outB;
wire outC;
wire outD;
wire outE;
wire outF;
Or OR0(in[0], in[1], outA);
Or OR2(in[2], outA, outB);
Or OR3(in[3], outB, outC);
Or OR4(in[4], outC, outD);
Or OR5(in[5], outD, outE);
Or OR6(in[6], outE, outF);
Or OR7(in[7], outF, out);
endmodule

View File

@ -11,5 +11,15 @@ module Xor(
);
// Put your code here:
wire nota;
wire notb;
Not NOT1(a, nota);
Not NOT2(b, notb);
wire w1;
wire w2;
And AND1(a, notb, w1);
And AND2(nota, b, w2);
Or OR(w1, w2, out);
endmodule

View File

@ -37,5 +37,64 @@ module ALU(
);
// Put your code here:
wire [15:0] xa;
wire [15:0] xb;
wire [15:0] xc;
wire [15:0] ya;
wire [15:0] yb;
wire [15:0] yc;
wire [15:0] xandy;
wire [15:0] xplusy;
wire [15:0] xf;
wire [15:0] xn;
wire [7:0] zri;
wire [7:0] zrj;
wire ngr;
wire zrm;
wire zrn;
wire zro;
wire tt;
wire ff;
// Mux16(a=x, b=false, sel=zx, out=xa);
// Not16(in=xa, out=xb);
// Mux16(a=xa, b=xb, sel=nx, out=xc);
Mux16 MUXX1(x, 16'b0, zx, xa);
Not16 NOTX1(xa, xb);
Mux16 MUXX2(xa, xb, nx, xc);
// Mux16(a=y, b=false, sel=zy, out=ya);
// Not16(in=ya, out=yb);
// Mux16(a=ya, b=yb, sel=ny, out=yc);
Mux16 MUXY1(y, 16'b0, zy, ya);
Not16 NOTY1(ya, yb);
Mux16 MUXY2(ya, yb, ny, yc);
// And16(a=xc, b=yc, out=xandy);
// Add16(a=xc, b=yc, out=xplusy);
// Mux16(a=xandy, b=xplusy, sel=f, out=xf);
And16 ANDZ1(xc, yc, xandy);
Add16 ADDZ1(xc, yc, xplusy);
Mux16 MUXZ1(xandy, xplusy, f, xf);
// Not16(in=xf, out=xn);
// Mux16(a=xf, b=xn, sel=no, out=out, out[15]=ngr, out[0..7]=zri, out[8..15]=zrj);
Not16 NOTF1(xf, xn);
Mux16 MUXF1(xf, xn, no, out);
assign ngr = out[15];
assign zri[7:0] = out[7:0];
assign zrj[7:0] = out[15:8];
// Or8Way(in=zri, out=zrm);
// Or8Way(in=zrj, out=zrn);
Or8Way OR8F1(zri, zrm);
Or8Way OR8F2(zrj, zrn);
Or ORF1(zrm, zrn, zro);
Not NOTF2(zro, zr);
Mux MUXF2(1'b0, 1'b1, ngr, ng);
// Or(a=zrm, b=zrn, out=zro);
// Not(in=zro, out=zr);
// Mux(a=false, b=true, sel=ngr, out=ng);
endmodule

View File

@ -12,5 +12,37 @@ module Add16(
);
// Put your code here:
wire carry0;
wire carry1;
wire carry2;
wire carry3;
wire carry4;
wire carry5;
wire carry6;
wire carry7;
wire carry8;
wire carry9;
wire carry10;
wire carry11;
wire carry12;
wire carry13;
wire carry14;
wire carry15;
HalfAdder HA0(a[0], b[0], out[0], carry0);
FullAdder FA0(a[1], b[1], carry0, out[1], carry1);
FullAdder FA1(a[2], b[2], carry1, out[2], carry2);
FullAdder FA2(a[3], b[3], carry2, out[3], carry3);
FullAdder FA3(a[4], b[4], carry3, out[4], carry4);
FullAdder FA4(a[5], b[5], carry4, out[5], carry5);
FullAdder FA5(a[6], b[6], carry5, out[6], carry6);
FullAdder FA6(a[7], b[7], carry6, out[7], carry7);
FullAdder FA7(a[8], b[8], carry7, out[8], carry8);
FullAdder FA8(a[9], b[9], carry8, out[9], carry9);
FullAdder FA9(a[10], b[10], carry9, out[10], carry10);
FullAdder FA10(a[11], b[11], carry10, out[11], carry11);
FullAdder FA11(a[12], b[12], carry11, out[12], carry12);
FullAdder FA12(a[13], b[13], carry12, out[13], carry13);
FullAdder FA13(a[14], b[14], carry13, out[14], carry14);
FullAdder FA14(a[15], b[15], carry14, out[15], carry15);
endmodule

View File

@ -12,5 +12,11 @@ module FullAdder(
);
// Put your code here:
wire sumi;
wire carryi;
wire carryj;
HalfAdder HA1(a, b, sumi, carryi);
HalfAdder HA2(c, sumi, sum, carryj);
Or OR(carryi, carryj, carry);
endmodule

View File

@ -11,5 +11,6 @@ module HalfAdder(
);
// Put your code here:
Xor XOR(a, b, sum);
And AND(a, b, carry);
endmodule

View File

@ -10,5 +10,9 @@ module Inc16(
);
// Put your code here:
wire [15:0] incr;
assign incr[15:0] = 16'b1;
Add16 ADD(in, incr, out);
// or just:
//assign out = in + 1;
endmodule

View File

@ -13,5 +13,9 @@ module Bit(
);
// Put your code here:
wire muxout;
// Mux(a=dffout, b=in, sel=load, out=muxout);
// DFF(in=muxout, out=out, out=dffout);
Mux MUX(out, in, load, muxout);
DFF DFF(clk, muxout, out);
endmodule

View File

@ -16,5 +16,47 @@ module BitShift8L(
);
// Put your code here:
reg [7:0] reg8;
always @(posedge clk) begin
if (load == 1) begin
reg8[7:0] = in[7:0];
end
else if (shift == 1 ) begin
reg8[7:1] = reg8[6:0];
reg8[0] = inLSB;
end
end
assign out = reg8;
// wire [7:0] out_l;
// wire [7:0] out_s;
// Mux MUXLA(out[0], in[0], load, out_l[0]);
// Mux MUXLB(out[1], in[1], load, out_l[1]);
// Mux MUXLC(out[2], in[2], load, out_l[2]);
// Mux MUXLD(out[3], in[3], load, out_l[3]);
// Mux MUXLE(out[4], in[4], load, out_l[4]);
// Mux MUXLF(out[5], in[5], load, out_l[5]);
// Mux MUXLG(out[6], in[6], load, out_l[6]);
// Mux MUXLH(out[7], in[7], load, out_l[7]);
// Mux MUXSA(out_l[0], inLSB, shift, out_s[0]);
// Mux MUXSB(out_l[1], out[0], shift, out_s[1]);
// Mux MUXSC(out_l[2], out[1], shift, out_s[2]);
// Mux MUXSD(out_l[3], out[2], shift, out_s[3]);
// Mux MUXSE(out_l[4], out[3], shift, out_s[4]);
// Mux MUXSF(out_l[5], out[4], shift, out_s[5]);
// Mux MUXSG(out_l[6], out[5], shift, out_s[6]);
// Mux MUXSH(out_l[7], out[6], shift, out_s[7]);
// Bit BITA(clk, out_s[0], 1'b1, out[0]);
// Bit BITB(clk, out_s[1], 1'b1, out[1]);
// Bit BITC(clk, out_s[2], 1'b1, out[2]);
// Bit BITD(clk, out_s[3], 1'b1, out[3]);
// Bit BITE(clk, out_s[4], 1'b1, out[4]);
// Bit BITF(clk, out_s[5], 1'b1, out[5]);
// Bit BITG(clk, out_s[6], 1'b1, out[6]);
// Bit BITH(clk, out_s[7], 1'b1, out[7]);
endmodule

View File

@ -16,5 +16,17 @@ module BitShift9R(
);
// Put your code here:
reg [8:0] reg9;
always @(posedge clk) begin
if (load == 1) begin
reg9[7:0] = in[7:0];
end
else if (shift == 1 ) begin
reg9[7:0] = reg9[8:1];
reg9[8] = inMSB;
end
end
assign out = reg9;
endmodule

View File

@ -7,12 +7,12 @@
module DFF(
input clk,
input in,
output out
output reg out
);
// No need to implement this chip
// This chip is implemented in verilog using reg-variables
reg out;
// reg out;
always @(posedge clk)
if (in) out <= 1'b1;
else out <= 1'b0;

View File

@ -17,5 +17,15 @@ module PC(
);
// Put your code here:
// wire [15:0] plusone;
// wire [15:0] incstep;
// wire [15:0] loadstep;
// wire [15:0] resetstep;
// Inc16 INC16(out, plusone);
// Mux16 MUX16A(out, plusone, inc, incstep);
// Mux16 MUX16B(incstep, in, load, loadstep);
// Mux16 MUX16C(loadstep, 16'b0, reset, resetstep);
wire [15:0] select;
assign select = reset? 0 : (load? in : (inc? out+1 : out));
Register REG(clk, select, 1'b1, out);
endmodule

View File

@ -14,5 +14,35 @@ module RAM3840(
);
// Put your code here:
wire load0;
wire load1;
wire load2;
wire load3;
wire load4;
wire load5;
wire load6;
wire load7;
wire [15:0] ram0;
wire [15:0] ram1;
wire [15:0] ram2;
wire [15:0] ram3;
wire [15:0] ram4;
wire [15:0] ram5;
wire [15:0] ram6;
wire [15:0] ram7;
DMux8Way DMUX(load, address[11:9],
load0, load1, load2, load3, load4, load5, load6, load7);
RAM512 RAM0(clk, address[8:0], in, load0, ram0);
RAM512 RAM1(clk, address[8:0], in, load1, ram1);
RAM512 RAM2(clk, address[8:0], in, load2, ram2);
RAM512 RAM3(clk, address[8:0], in, load3, ram3);
RAM512 RAM4(clk, address[8:0], in, load4, ram4);
RAM512 RAM5(clk, address[8:0], in, load5, ram5);
RAM512 RAM6(clk, address[8:0], in, load6, ram6);
RAM256 RAM7(clk, address[7:0], in, load7, ram7);
Mux8Way16 MUX(ram0, ram1, ram2, ram3, ram4, ram5, ram6, ram7,
address[11:9], out);
endmodule

View File

@ -14,5 +14,13 @@ module RAM512(
);
// Put your code here:
wire load0;
wire load1;
wire [15:0] ram0;
wire [15:0] ram1;
DMux DMUX(load, address[8], load0, load1);
RAM256 RAM0(clk, address[7:0], in, load0, ram0);
RAM256 RAM1(clk, address[7:0], in, load1, ram1);
Mux16 MUX(ram0, ram1, address[8], out);
endmodule

View File

@ -14,5 +14,20 @@ module Register(
);
// Put your code here:
Bit BITA(clk, in[0], load, out[0]);
Bit BITB(clk, in[1], load, out[1]);
Bit BITC(clk, in[2], load, out[2]);
Bit BITD(clk, in[3], load, out[3]);
Bit BITE(clk, in[4], load, out[4]);
Bit BITF(clk, in[5], load, out[5]);
Bit BITG(clk, in[6], load, out[6]);
Bit BITH(clk, in[7], load, out[7]);
Bit BITI(clk, in[8], load, out[8]);
Bit BITJ(clk, in[9], load, out[9]);
Bit BITK(clk, in[10], load, out[10]);
Bit BITL(clk, in[11], load, out[11]);
Bit BITM(clk, in[12], load, out[12]);
Bit BITN(clk, in[13], load, out[13]);
Bit BITO(clk, in[14], load, out[14]);
Bit BITP(clk, in[15], load, out[15]);
endmodule

View File

@ -3,3 +3,10 @@
// read the button state and output to led
// Put your code here:
@BUT
D=M
@LED
M=!D
@0
0;JMP

View File

@ -31,8 +31,41 @@ M=1
// Put your code here:
@R2
M=0
@DEBUG2
M=0
@itr
M=0
// loop declaration
// D = R1 - itr
// if 0 jump to @STOP
// else continue
(LOOP)
@itr
D=M
@R0
D=M-D
@DEBUG0
M=D
@END
D;JEQ
// R2 = R0 + R2
// itr = itr + 1
@R1
D=M
@R2
DM=D+M
@DEBUG2
M=D
@itr
M=M+1
// back to loop declaration
@LOOP
0;JMP
// till here!

View File

@ -36,5 +36,71 @@ module CPU(
);
// Put your code here:
wire loadA;
wire loadD;
wire is_A;
wire is_C;
wire zr;
wire ng;
wire inc;
wire load;
wire jump;
wire [15:0] toA;
wire [15:0] toD;
wire [15:0] toPC;
wire [15:0] fromA;
wire [15:0] fromD;
wire [15:0] fromPC;
wire [15:0] fromAorM;
wire [15:0] fromALU;
reg [15:0] tempM;
reg [15:0] tempPC;
assign is_C = instruction[15] & instruction[14] & instruction[13];
assign is_A = ~is_C;
assign loadD = is_C & instruction[4];
assign loadA = (is_C & instruction[5]) || is_A;
assign fromAorM = instruction[12] ? inM : fromA;
assign toA = is_A ? instruction : outM;
// jump if j1 bit set and ng bit set
// jump if j2 bit set and zr bit set
// jump if j3 bit set and zr, ng bit not set
assign jump = is_C
& ((instruction[2] & ng)
|| (instruction[1] & zr)
|| (instruction[0] & ~(zr | ng)));
assign inc = ~jump;
assign outM = fromALU;
//assign toPC = jump? fromA : pc;
//xxxx xxxx xxxx xxxx
Register RegA(clk, toA, loadA, fromA);
Register RegD(clk, fromALU, loadD, fromD);
PC PC(clk, fromA, jump, inc, reset, pc);
ALU ALU(
fromD,
fromAorM,
instruction[11],
instruction[10],
instruction[9],
instruction[8],
instruction[7],
instruction[6],
fromALU,
zr,
ng
);
assign addressM = fromA;
assign writeM = is_C & instruction[3];
endmodule

View File

@ -6,10 +6,22 @@
`default_nettype none
module Clock25_Reset20(
input CLK, // external clock 100 MHz
output clk, // internal clock 25 Mhz
output reset // reset signal approx. 20us
output reg clk, // internal clock 25 Mhz
output reg reset // reset signal approx. 20us
);
// Put your code here:
reg boot=1;
reg [3:0] ccount=0;
reg [12:0] rcount=0;
always @(posedge CLK) begin
if (boot == 1) begin
boot <= (rcount == 4095) ? 0 : 1;
rcount <= (rcount == 4095) ? 0 : rcount + 1;
reset <= (rcount >= 2048) ? 0 : 1;
end
ccount <= (ccount == 3) ? 0 : ccount + 1;
clk <= (ccount >= 2) ? 1 : 0;
end
endmodule

View File

@ -14,6 +14,83 @@ module HACK(
output [1:0] LED // leds (0 off, 1 on)
);
wire loadRAM;
wire loadIO0;
wire loadIO1;
wire loadIO2;
wire loadIO3;
wire loadIO4;
wire loadIO5;
wire loadIO6;
wire loadIO7;
wire loadIO8;
wire loadIO9;
wire loadIOA;
wire loadIOB;
wire loadIOC;
wire loadIOD;
wire loadIOE;
wire loadIOF;
wire [15:0] inRAM;
wire [15:0] inIO0;
wire [15:0] inIO1;
wire [15:0] inIO2=0;
wire [15:0] inIO3=0;
wire [15:0] inIO4=0;
wire [15:0] inIO5=0;
wire [15:0] inIO6=0;
wire [15:0] inIO7=0;
wire [15:0] inIO8=0;
wire [15:0] inIO9=0;
wire [15:0] inIOA=0;
wire [15:0] inIOB;
wire [15:0] inIOC;
wire [15:0] inIOD;
wire [15:0] inIOE;
wire [15:0] inIOF;
wire writeM;
wire [15:0] inM;
wire [15:0] instruction;
wire [15:0] outM;
wire [15:0] addressM;
wire [15:0] pc;
wire clk, reset;
wire [15:0] outDEBUG0;
wire [15:0] outDEBUG1;
wire [15:0] outDEBUG2;
wire loadDEBUG0;
wire loadDEBUG1;
wire loadDEBUG2;
// Put your code here:
assign LED[1:0] = inIO0[1:0];
assign outDEBUG0 = inIOB;
assign outDEBUG1 = inIOC;
assign outDEBUG2 = inIOD;
assign loadDEBUG0 = loadIOB;
assign loadDEBUG1 = loadIOC;
assign loadDEBUG2 = loadIOD;
Clock25_Reset20 CLKR(CLK, clk, reset);
CPU CPU(clk, inM, instruction, reset, outM, writeM, addressM, pc);
Memory Memory(addressM, writeM, inM, loadRAM,
loadIO0, loadIO1, loadIO2, loadIO3, loadIO4, loadIO5, loadIO6, loadIO7,
loadIO8, loadIO9, loadIOA, loadIOB, loadIOC, loadIOD, loadIOE, loadIOF,
inRAM, inIO0, inIO1, inIO2, inIO3, inIO4, inIO5, inIO6, inIO7,
inIO8, inIO9, inIOA, inIOB, inIOC, inIOD, inIOE, inIOF);
ROM ROM(pc, instruction);
RAM3840 RAM(clk, addressM[11:0], outM, loadRAM, inRAM);
Register LED12(clk, outM, loadIO0, inIO0);
Register BUT12(clk, {14'b0, BUT[1:0]}, 1'b1, inIO1);
Register DEBUG0(clk, outM, loadIOB, inIOB);
Register DEBUG1(clk, outM, loadIOC, inIOC);
Register DEBUG2(clk, outM, loadIOD, inIOD);
Register DEBUG3(clk, outM, loadIOE, inIOE);
Register DEBUG4(clk, outM, loadIOF, inIOF);
endmodule

View File

@ -56,5 +56,40 @@ module Memory(
);
// Put your code here:
wire selA;
wire selB;
wire loadA;
wire loadB;
wire [15:0] outA;
wire [15:0] outB;
wire [15:0] outAB;
DMux DMUX(address[12], address[3], selA, selB);
And ANDA(selA,load,loadA);
And ANDB(selB,load,loadB);
And ANDR(~address[12], load, loadRAM);
DMux8Way DMUXLOADA(loadA, address[2:0],
loadIO0, loadIO1, loadIO2, loadIO3,
loadIO4, loadIO5, loadIO6, loadIO7);
DMux8Way DMUXLOADB(loadB, address[2:0],
loadIO8, loadIO9, loadIOA, loadIOB,
loadIOC, loadIOD, loadIOE, loadIOF);
Mux8Way16 Mux8Way16A(
inIO0[15:0], inIO1[15:0], inIO2[15:0], inIO3[15:0],
inIO4[15:0], inIO5[15:0], inIO6[15:0], inIO7[15:0],
address[2:0], outA[15:0]
);
Mux8Way16 Mux8Way16B(
inIO8[15:0], inIO9[15:0], inIOA[15:0], inIOB[15:0],
inIOC[15:0], inIOD[15:0], inIOE[15:0], inIOF[15:0],
address[2:0], outB[15:0]
);
Mux16 MUX16AB(outA[15:0], outB[15:0], address[3], outAB[15:0]);
Mux16 MUX16ABR(inRAM[15:0], outAB[15:0], address[12], out[15:0]);
endmodule