In this problem, you will write two Verilog modules. You may describe both modul
ID: 3903357 • Letter: I
Question
In this problem, you will write two Verilog modules. You may describe both modules in the same file. Name your file consistently with the top-level module, which in this case is the 4-bit adder. Write a structural model using Verilog primitives for a 1-bit full adder. Use the following module declaration and port declaration to define the circuit a. module adderlbit (a, b, cin, s, cout) input a, b, cin,; output s, cout; /7 Addends a and b, and carry-in cin // Sum s and carry-out cout INSERTTHE CODE FOR YOUR STRUCTURAL 1-BIT ADDER HERE endmodule Add wire declarations as needed by the structure of the circuit you are describing in Verilog. You may use AND gates, OR gates, and inverters. Your AND gates and OR gates may have any number of inputs. Create a model for a 4-bit adder. Your model should instantiate four instances of your 1-bit full adder. Use the following module declaration and port declaration as the framework for your module. b. module adder4bit (A, B, Cin, S, Cout); input13:0] A, B; input output [3:0] S; output // Two 4-bit addends // 1-bit carry-in to the LSB //The 4-bit sum. // 1-bit carry-out from the MSB Cin; Cout /INSERT THE CODE FOR YOUR STRUCTURAL 4-BIT ADDER HERE // DO THIS BY INSTANTIATING FOUR INSTANCES OF THE 1-BIT ADDER /APPLY THE CORRECT INPUTS OF THIS MODULE TO THE INSTANCES // USE WIRES TO CONNECT THE 1-BIT ADDERS TOGETHER AS NEEDED endmoduleExplanation / Answer
The details of modules is given below with comments:
module adder1bit(a,b,cin,s,cout);
input a,b,cin;
output s,out;
wire a,b,cin;
reg s,cout;
//since only and, or and not is allowed.
assign s = (!(((!a) &b) | ((!b) & a)) & cin) | (((!a) &b) | ((!b) & a) & !cin) ; //a ^ b ^ cin where ^ is XOR
//you could also use s = (!a & b & c) | (a & !b & !c)|(a & b & c)|(!a & !b & c) after simplification of above expression of XOR since XOR can't be used
assign cout = (a & b) | (cin & !a & b) | (cin& a & !b); //ab + cin(a^b)
endmodule
module adder4bit(A,B,Cin,S,Cout);
input [3:0] A,B;
input Cin;
output [3:0] S;
output Cout;
wire A,B,Cin;
wire [2:0] temp; //wire to connect the cout of every 1bit adder as cin to next adder
reg S, Cout;
adder1bit(A[0],B[0],Cin,S[0],temp[0]);
adder1bit(A[1],B[1],temp[0],S[1],temp[1]);
adder1bit(A[2],B[2],temp[1],S[2],temp[2]);
adder1bit(A[3],B[3],temp[2],S[3],Cout);
endmodule
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.