Question

In: Electrical Engineering

In Verilog, implement a circuit capable of adding and subtracting 8-bit binary numbers. You should submit...

In Verilog, implement a circuit capable of adding and subtracting 8-bit binary numbers. You should submit a single Verilog file that contains all of the necessary modules and also contain a module named top(A, B, sel, F, C).

For the selection, use a 0 to select Addition and a 1 to select Subtraction.

Solutions

Expert Solution

// verilog code full adder

module full_adder (

input A,B,Cin,

output S,Cout);

  

assign S = (A ^ B ^ Cin);

assign Cout = ( A & B ) | ( B & Cin) | (A & Cin) ;

  

endmodule

//verilog code for exor gate

module xor_gate (

input A,B,

output Y );

  

assign Y = A ^ B ;

  

endmodule

//verilog code for 8 bit adder/subtractor module

module add_sub_8bit (

  

//input ports declarations

input [7:0] A,B,

input sel,

  

//output port declarations

output [7:0] F,

output C

);

  

  

//internal signal declarations

wire [7:0] x ;

wire [6:0] c ;

  

//instantiation of xor gates

xor_gate U0 ( sel , B[0] , x[0] );

xor_gate U1 ( sel , B[1] , x[1] );

xor_gate U2 ( sel , B[2] , x[2] );

xor_gate U3 ( sel , B[3] , x[3] );

xor_gate U4 ( sel , B[4] , x[4] );

xor_gate U5 ( sel , B[5] , x[5] );

xor_gate U6 ( sel , B[6] , x[6] );

xor_gate U7 ( sel , B[7] , x[7] );

  

//instantiaion of full adders

full_adder F0 ( A[0] , x[0] , sel , F[0] , c[0] );

full_adder F0 ( A[1] , x[1] , c[0] , F[1] , c[1] );

full_adder F0 ( A[2] , x[2] , c[1] , F[2] , c[2] );

full_adder F0 ( A[3] , x[3] , c[2] , F[3] , c[3] );

full_adder F0 ( A[4] , x[4] , c[3] , F[4] , c[4] );

full_adder F0 ( A[5] , x[5] , c[4] , F[5] , c[5] );

full_adder F0 ( A[6] , x[6] , c[5] , F[6] , c[6] );

full_adder F0 ( A[7] , x[7] , c[6] , F[7] , C );

  

  

endmodule

// verilog testbench code for 8 bit adder/subtractor

module test ;

  

reg [7:0] A,B;

reg sel;

  

wire [7:0] F;

wire C;

  

//instantiate UUT (unit under test)

add_sub_8bit UUT (.A(A),.B(B),.sel(sel),.F(F),.C(C));

  

//input stimulus generations

initial begin

$dumpfile ("waves.vcd");

$dumpvars;

A = 8'b00101101 ; B = 8'b00101101; sel = 1'b0; #10;

A = 8'b00100101 ; B = 8'b00100001; sel = 1'b1; #10;

A = 8'b00100001 ; B = 8'b00101101; sel = 1'b0; #10;

A = 8'b00100000 ; B = 8'b00100001; sel = 1'b1; #10;

A = 8'b10101101 ; B = 8'b00101101; sel = 1'b0; #10;

A = 8'b11101111 ; B = 8'b00100000; sel = 1'b1; #10;

$finish;

end

  

  

endmodule

// I verified design code with simulation and waveforms are attached below;


Related Solutions

The result of subtracting the following two signed binary numbers on an eight bit machine is...
The result of subtracting the following two signed binary numbers on an eight bit machine is      10110011    - 01101001
Represent -60 in binary using 8-bit signed magnitude. Add the following unsigned 8 bit binary numbers...
Represent -60 in binary using 8-bit signed magnitude. Add the following unsigned 8 bit binary numbers as shown. 01110101 + 00111011 Add the following unsigned 8 bit binary numbers as shown. 01000100 + 10111011
Design an 8-bit adder. Show the truth table, logic circuit, and Verilog code.
Design an 8-bit adder. Show the truth table, logic circuit, and Verilog code.
Design an 8-bit adder. Show the truth table, logic circuit, and Verilog code.
Design an 8-bit adder. Show the truth table, logic circuit, and Verilog code.
Implement 4-bit binary adder/subtractor using gate level. ( verilog code and test bench)
Implement 4-bit binary adder/subtractor using gate level. ( verilog code and test bench)
Convert the following numbers to 8-bit binary and 8-bit hexadecimal: a) 20 b) 78 c) -25...
Convert the following numbers to 8-bit binary and 8-bit hexadecimal: a) 20 b) 78 c) -25 d) -96 Convert the following hexadecimal numbers to binary and decimal assuming two's compliment format: a) 0x56 b) 0x14 c) 0xF8 d) 0xCC MUST DO ALL PROBLEMS AND SHOW ALL WORK!!!!
Write a Verilog code to implement 16 bit LFSR
Write a Verilog code to implement 16 bit LFSR
please i need the code for an 8 bit by 8 bit multiplier in verilog ....
please i need the code for an 8 bit by 8 bit multiplier in verilog . ( pls the code should be clearly written and BOLD)
1. Please convert the following decimal numbers to 8-bit binary sign magnitude and to 8-bit 2’s...
1. Please convert the following decimal numbers to 8-bit binary sign magnitude and to 8-bit 2’s complement. Please show your work if there are multiple steps. Sign Magnitude 2’s complement a. +67 b. +40 c. -28 d. -40
Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to...
Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to implement this.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT