Please code the following in Verilog:
module Add_half (
input a, b,
output c_out, sum
);
xor G1 (sum, a, b);
and G2 (c_out, a, b);
endmodule
module Add_full (
input a, b, c_in,
output c_out, sum
);
wire w1, w2, w3, w4;
Add_half M1 (a, b, w1, w2);
Add_half M2 (w2, c_in, w3, sum);
or O1 (c_out, w1, w3);
endmodule
module Adder_subtractor (
input [3:0] a, b, // A and B input
input M, // mode input
output [3:0] sum,
output c_out
);
wire [3:0] x;
wire c1, c2, c3;
xor G0 (x[0], b[0], M);
xor G1 (x[1], b[1], M);
xor G2 (x[2], b[2], M);
xor G3 (x[3], b[3], M);
Add_full m0 (.a(a[0]), .b(x[0]), .c_in(M), .sum(sum[0]),
.c_out(c1));
Add_full m1 (.a(a[1]), .b(x[1]), .c_in(c1), .sum(sum[1]),
.c_out(c2));
Add_full m2 (.a(a[2]), .b(x[2]), .c_in(c2), .sum(sum[2]),
.c_out(c3));
Add_full m3 (.a(a[3]), .b(x[3]), .c_in(c3), .sum(sum[3]),
.c_out(c_out));
endmodule
//TestBench
module top;
reg [3:0] a, b;
reg M;
wire [3:0] sum;
wire c_out;
integer i,j;
Adder_subtractor dut (.a(a), .b(b), .M(M), .c_out(c_out), .sum(sum));
initial begin
$monitor("a = %b b = %b M = %b c_out = %b sum = %b", a, b, M,
c_out, sum);
M = 1'b0;
for (i = 5; i < 8 ; i = i + 1) begin
for (j = 6; j < 9 ; j = j + 1) begin
a = i; b = j; #20;
end
end
M = 1'b1;
for (i = 6; i < 8 ; i = i + 1) begin
for (j = 0; j < 5 ; j = j + 1) begin
a = i; b = j; #20;
end
end
end
endmodule
/******************* OUTPUT OF PROGRAM ********************
a = 0101 b = 0110 M = 0 c_out = 0 sum = 1011
a = 0101 b = 0111 M = 0 c_out = 0 sum = 1100
a = 0101 b = 1000 M = 0 c_out = 0 sum = 1101
a = 0110 b = 0110 M = 0 c_out = 0 sum = 1100
a = 0110 b = 0111 M = 0 c_out = 0 sum = 1101
a = 0110 b = 1000 M = 0 c_out = 0 sum = 1110
a = 0111 b = 0110 M = 0 c_out = 0 sum = 1101
a = 0111 b = 0111 M = 0 c_out = 0 sum = 1110
a = 0111 b = 1000 M = 0 c_out = 0 sum = 1111
a = 0110 b = 0000 M = 1 c_out = 1 sum = 0110
a = 0110 b = 0001 M = 1 c_out = 1 sum = 0101
a = 0110 b = 0010 M = 1 c_out = 1 sum = 0100
a = 0110 b = 0011 M = 1 c_out = 1 sum = 0011
a = 0110 b = 0100 M = 1 c_out = 1 sum = 0010
a = 0111 b = 0000 M = 1 c_out = 1 sum = 0111
a = 0111 b = 0001 M = 1 c_out = 1 sum = 0110
a = 0111 b = 0010 M = 1 c_out = 1 sum = 0101
a = 0111 b = 0011 M = 1 c_out = 1 sum = 0100
a = 0111 b = 0100 M = 1 c_out = 1 sum = 0011
*********************************************************/
Please code the following in Verilog: Write the HDL gate-level hierarchical description of a four-bit adder-subtractor...
Write the HDL gate-level hierarchical description of a four-bit adder-subtractor for unsigned binary numbers. You can instantiate the four-bit full adder. Write a test bench to test your module.
Building and testing basic combinational circuits using Verilog HDL Description: Build and test the following circuits using gate-level modeling in Verilog HDL 1.3-input majority function 2.Conditional inverter (see the table below: x - control input, y -data input). Do NOT use XOR gates for the implementation. Output 3. Two-input multiplexer (see the table below: x.y -data inputs, z- control input) Output 4. 1-bit half adder. 5. 1-bit full adder by cascading two half adders 6.1-bit full adder directly (as in...
Write an Verilog code for a 8-bit subtractor (Bits are in 1's complement) using the following: 1. 5-bit parallel adder 2. 3-bit parallel adder The condition are as follows: 1. The Most Significant bits of the subtractor must be given to the 5-bit parallel adder. 2, The Least Significant bits of the subtractor must be given to the 3-bit parallel adder. 3. The input A will be assign to the switches with the least significant bit A[0] linked to SW0....
Construct the 8-bit ripple-carry adder/subtractor for signed integers. Negative numbers are in the 2's complement form. The circuit has inputs X(7:0), Y(7:0), CO, M and outputs S(7:0), carry-out of MSB C8, OFL (OFL 1 when it occurs). The circuit should perform addition and subtraction of 8-bit signed numbers 2. with M-1 and M-0, respectively. a) Obtain the schematic for the 8-bit adder/subtractor with two 4-bit adder/subtractors from problem 1 as building blocks. X, Y, A, B, S can be shown...
Building and testing basic combinational circuits using Verilog HDL Description: Build and test the following circuits using gate-level modeling in Verilog HDL. 1. 3-input majority function. 2. Conditional inverter (see the table below: x - control input, y - data input). Do NOT use XOR gates for the implementation. x y Output 0 y 1 y' 3. Two-input multiplexer (see the table below: x,y - data inputs, z - control input). z Output 0 x 1 y 4. 1-bit half...
Implement the 8-bit Gate level ALU shown in the figure below in VHDL (Full adder & subtractor & all logical operations & flags implementations) 31 ALUControlo Sum31 ALUContro out Sum 10 0 00 ALUControl 、ノ Resullgi Negative Zero Result ALUFlags o Verflow Figure 1 N-bit ALU with output flags 31 ALUControlo Sum31 ALUContro out Sum 10 0 00 ALUControl 、ノ Resullgi Negative Zero Result ALUFlags o Verflow Figure 1 N-bit ALU with output flags
Question: Part 1: In the second part of this lab, we will extend our adder to also allow for subtraction of the second number from the first. To implement this, we must take the 2's compliment of the second number and add it to the first. This can be implemented using the circuit shown in Section 4.4.2 of the notes, which is shown again here in Figure 2. B3 A3 B2 A B, A, B, A, -SM 0: Add 1:...
(32 pts) Adder/ Subtractor 11. (8 pts) Given a l-bit full adder (you can use the box representation as below) show the circuitry required to make it into a 4-bit full adder and subtractor. 12. (12 pts) Show the hardware required to compute the 4 primary flags for your 4-bit add sub unit carry (C), zero (Z), overflow (V), and sign (N). 13.(12 pts) Show the results for the addition below. Also show the equivalent decimal numbers for each Ain...
4. Design a 4-bit Adder / Subtractor. Follow the steps given below. (a) Write the VHDL code for a 1-bit Full Adder. The VHDL code must include an entity and an architecture. (b) Draw the circuit diagram for a 4-bit Adder / Subtractor. The circuit diagram may include the following logic elements: 1-bit Full Adders (shown as a block with inputs and outputs) Any 2-input logic gates Multiplexers Do not draw the logic circuit for the 1-bit Full Adder.
need help please thanks! Draw a gate-level schematic for the fall-adder module. XOR gates can be used to usplement Sotput; two levels ofNAND ples are handy for tn lema îngC, as a sum of products Create a MOSFET cirout for each of the logic gates you used in step 1 Your lab assigment this week is to design and test a CMOS circuit that performs addition Some suggestions on how to proceed Let's start with a simple ripple-cany adder based...