Question

In: Electrical Engineering

Design a 3-bit 2’s complement adder/subtractor with overflow flag detection Design and simulate a structural model...

Design a 3-bit 2’s complement adder/subtractor with overflow flag detection

Design and simulate a structural model (not behavioral) of a 3-bit Adder/Subtractor). Use the 3-bit carry propagate adder of the project as a module for your adder/subtractor. The inputs A and B should be positive binary numbers where vector B must be converted to a negative 2's complement when a subtraction operation is configured. When m=0 it should perform and addition (A+B) and if m=1 it should perform a subtraction operation (A-B)

Your module ports (inputs and outputs), should be as follow:

module add_sub(

   input [2:0] a, b,

   input m,   // m=0 => addition (a+b);   m=1 => subtraction (a-b)

   output [2:0] result,  

   output overflow

);

/* your wire declarations, n-bit adder and xor gates

go in this section */

endmodule

Create a test bench to test the following 2’s complement cases:

a = 3’b001 b = 3’b001 m = 1’b0     // (1+1=2) => result = 3’b010;  overflow = 1’b0

a = 3’b011 b = 3’b010 m = 1’b1   // (3-2=1) => result = 3’b001;   overflow = 1’b0  

a = 3’b011 b = 3’b010 m = 1’b0     // (3+2=5) =>  result = 3’b101;  overflow = 1’b1   Overflow Error!

a = 3’b110 b = 3’b101 m = 1’b0     // (-2-3)=-5) => result = 3’b011; overflow = 1’b1   Overflow Error!

Your Testbench should clearly display the inputs and output results

=============full_adder.v====================

//full_adder.v

module full_adder
(
input a,b,ci,
output s, co
);

wire w1, w2, w3;

xor x1(w1, a, b);
xor x2(s, w1, ci);
nand n1(w2, w1, ci);
nand n2(w3, a, b);
nand n3(co, w2, w3);

endmodule

Solutions

Expert Solution

//verilog module

module add_sub(a,b,m,result,overflow);

input[2:0]a,b;
input m;
  
output [2:0]result;
  
output overflow;
  
wire [2:0]temp;
wire [2:0]t_c;
  
xor n1(temp[2],b[2],m);
xor n2(temp[1],b[1],m);
xor n3(temp[0],b[0],m);


// Full after instance given is used


full_adder n4(a[0],temp[0],m,result[0],t_c[0]);
full_adder n5(a[1],temp[1],t_c[0],result[1],t_c[1]);
full_adder n6(a[2],temp[2],t_c[1],result[2],t_c[2]);

xor n7(overflow,t_c[2],t_c[1]);
  
endmodule

//full adder instance module

module full_adder
(
input a,b,ci,
output s, co
);

wire w1, w2, w3;

xor x1(w1, a, b);
xor x2(s, w1, ci);
nand n1(w2, w1, ci);
nand n2(w3, a, b);
nand n3(co, w2, w3);

endmodule

//testbench

module test;

reg [2:0]a,b;
reg m;
  
wire [2:0] result;
wire overflow;
  
add_sub dut (a,b,m,result,overflow);
  
initial
begin
$dumpfile("var.vcd");
$dumpvars;
a=3'b001;b=3'b001;m=1'b0;#30;//(1+1=2)=> result=3'b010; overflow=1'b0
a=3'b011;b=3'b010;m=1'b1;#30;//(3-2=1)=> result=3'b001;overflow=1'b0
a=3'b011;b=3'b010;m=1'b0;#30;//(3+2=5)=> result=3'101;overflow=1'b1 overflow Error
a=3'b110;b=3'b101;m=1'b0;#30;//(-2-3=-5)=> result=3'b011;overflow=1'b1 overflow Error
$finish;
  
end
endmodule

Simulated waveform


Related Solutions

Design of 4 Bit Adder/Subtractor using Loops (Behavior Modeling Style) (verilog Code) -
Design of 4 Bit Adder/Subtractor using Loops (Behavior Modeling Style) (verilog Code) -
Make a 2 bit binary adder subtractor multiplier on verilog and display it on seven segment...
Make a 2 bit binary adder subtractor multiplier on verilog and display it on seven segment using fpga
Design and implementation 4-bit binary full adder with fast carry using behavioral and structural style of...
Design and implementation 4-bit binary full adder with fast carry using behavioral and structural style of modelling. (LS 7483) I want logic diagram and its truth table also i want code for it in VDHL software
Design and implementation 4-bit binary full adder with fast carry using behavioral and structural style of...
Design and implementation 4-bit binary full adder with fast carry using behavioral and structural style of modelling. (LS 7483) i want logic diagram and truth table
7 – For the following operations: • write the operands as 4-bit 2's complement binary numbers,...
7 – For the following operations: • write the operands as 4-bit 2's complement binary numbers, • perform the operation shown, • show all work in binary operating on 4-bit numbers, and • identify overflow if necessary. a) 4 + 2 b) 4 – 2 c) 2 – 4 d) 4 + 4
add the following numbers using 16-bit 2's complement. show all the steps and calculations. Please also...
add the following numbers using 16-bit 2's complement. show all the steps and calculations. Please also show steps to verify that the answer is correct. -7493 and -6372
Input pin(s): inputw [1], sysclock [1] Output pin(s): outputq [1] Design a 3-bit parity generator using...
Input pin(s): inputw [1], sysclock [1] Output pin(s): outputq [1] Design a 3-bit parity generator using a minimal state table for a Moore model FSM. For every three bits that are observed on inputw during three consecutive clock cycles, the FSM generates the parity bit outputq = 1 if the number of 1s received in the sequence so far is odd. Must use a maximum of 3 flip flops.
Please write in multisim: Design 3 bit a synchronous counter to produce the following sequence: 0, 1, 2, 5, 3 then 0.by using...
Please write in multisim: Design 3 bit a synchronous counter to produce the following sequence: 0, 1, 2, 5, 3 then 0.by using J-K Filp Flop.. Please i need in multisim and Step of solution. Thanks!!
Complete this vocabulary 1-p-hat 2-sample 3-chance model 4-Statistic ( not statistics ) 5-Simulate 6-Strength of evidence...
Complete this vocabulary 1-p-hat 2-sample 3-chance model 4-Statistic ( not statistics ) 5-Simulate 6-Strength of evidence 7-Observational units 8-Variable 9-Parameter 10- Plausible
Consider the following growth model and answer the questions below. (1) S=I (2) S=sY (3) Y=F(K,AL),...
Consider the following growth model and answer the questions below. (1) S=I (2) S=sY (3) Y=F(K,AL), λY=F(λK,λAL) (4) K^'=I-δK 0<δ<1 (5) L^'=nL n>0 (6) A^'=gA g>0 Endogenous (6): , , , , ,   Predetermined (3): K, L, A Initial Conditions (3): K_0, L_0, A_0 Exogenous (5): n, g, s, δ 1. Show that equations (1)-(6) reduce to the two intensive form equations y=f(k) k^'=sy-[n+g+δ]k where k=K/AL , y=Y/AL   2. Show in a diagram how an increase in the rate of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT