📄 alu64_struct.v
字号:
// Structural ALU`define SIZE 64module mux2(sel, op0, op1, res); input sel; input op0; input op1; output res; wire not_sel; not n(not_sel,sel); wire op0p; and a1(op0p,not_sel,op0); wire op1p; and a2(op1p,sel,op1); or o(res,op0p,op1p);endmodulemodule mux4(sel, op0, op1, op2, op3, res); input [1:0] sel; input op0; input op1; input op2; input op3; output res; wire res1; mux2 m1(sel[0],op0,op1,res1); wire res2; mux2 m2(sel[0],op2,op3,res2); mux2 m3(sel[1],res1,res2,res); // can be optimized!endmodulemodule alu1(func, opa, opb, cin, result, cout); input [2:0] func; input opa; input opb; input cin; // cin for add, borrow for sub! output cout; output result; wire not_opb; not n1(not_opb,opb); wire relevant_opb; mux2 m1(func[0],opb,not_opb,relevant_opb); wire res0; // result of equivalence/xor xnor n2(res0,opa,relevant_opb); wire res1; // result of and/bic and a1(res1,opa,relevant_opb); wire res2; // result of bis/ornot or o1(res2,opa,relevant_opb); wire res3; // result of add/sub xor n3(res3,opa,opb,cin); mux4 m2({func[2],func[1]},res0,res1,res2,res3,result); wire relevant_a; wire not_opa; not n4(not_opa,opa); mux2 m3(func[0],opa,not_opa,relevant_a); wire sig1; and a2(sig1,relevant_a,opb); wire sig2; and a3(sig2,relevant_a,cin); wire sig3; and a5(sig3,cin,opb); and a6(cout,sig1,sig2,sig3);endmodulemodule alu8(func, opa, opb, cin, result, cout); input [2:0] func; input [7:0] opa; input [7:0] opb; input cin; output [7:0] result; output cout; wire c0; alu1 a0(func, opa[0],opb[0],cin,result[0],c0); wire c1; alu1 a1(func, opa[1],opb[1],c0,result[1],c1); wire c2; alu1 a2(func, opa[2],opb[2],c1,result[2],c2); wire c3; alu1 a3(func, opa[3],opb[3],c2,result[3],c3); wire c4; alu1 a4(func, opa[4],opb[4],c3,result[4],c4); wire c5; alu1 a5(func, opa[5],opb[5],c4,result[5],c5); wire c6; alu1 a6(func, opa[6],opb[6],c5,result[6],c6); alu1 a7(func, opa[7],opb[7],c6,result[7],cout);endmodulemodule alu64(func, opa, opb, result, cout);/*** I/Os **********/ input [2:0] func; input [`SIZE-1:0] opa; input [`SIZE-1:0] opb; output [`SIZE-1:0] result; output cout;/*** end of I/Os *****/ wire c1; alu8 a1(func, opa[7:0],opb[7:0],1'b0, result[7:0],c1); wire c2; alu8 a2(func, opa[15:8],opb[15:8],c1, result[15:8],c2); wire c3; alu8 a3(func, opa[23:16],opb[23:16],c2, result[23:16],c3); wire c4; alu8 a4(func, opa[31:24],opb[31:24],c3, result[31:24],c4); wire c5; alu8 a5(func, opa[39:32],opb[39:32],c4, result[39:32],c5); wire c6; alu8 a6(func, opa[47:40],opb[47:40],c5, result[47:40],c6); wire c7; alu8 a7(func, opa[55:48],opb[55:48],c6, result[55:48],c7); alu8 a8(func, opa[63:56],opb[63:56],c7, result[63:56],cout);endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -