Question

Write an Verilog code for a 8-bit subtractor (Bits are in 1's complement) using the following:...

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. Similarly A[1] should be linked to SW1 , A[2] to SW2 and so on.

4. The input B will be assign to the switches with the least significant bit B[0] linked to SW8, Similarly B[1] should be linked to SW9, B[2] to SW10 and so on.

5. The output S will be assign to the LEDs with the least significant bit S[0] linked to LD0, Similarly S[1] should be linked to LD1, S[2] to LD2 and so on.

6. LD15 will be used to represent the carry bit of final output S.

7. The addition and subtraction operators (+,-) are not allowed in the codes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

one bit adder:

module adder_1bit(a,b,cin,sum,cy);
input a,b,cin;
output wire sum,cy;
assign sum= a ^ b ^ cin;
assign cy= (a &( b))|(cin&(a^(b)));
endmodule

Here by one bit module instantiations the 3 bit and 5 bit adders are designed .

3_bit adder:

module adder_3bit(a,b,cin,sum,cy);
input [2:0]a,b;
input cin;
output [2:0] sum;
output cy;
wire c0,c1;
adder_1bit z1(a[0],b[0],cin,sum[0],c0);
adder_1bit z2(a[1],b[1],c0,sum[1],c1);
adder_1bit z3(a[2],b[2],c1,sum[2],cy);
endmodule

5_bit adder:

module adder_5bit(a,b,cin,sum,cy);
input [4:0]a,b;
input cin;
output [4:0] sum;
output cy;
wire [3:0]c;
adder_1bit zz2(a[0],b[0],cin,sum[0],c[0]);
adder_1bit zz3(a[1],b[1],c[0],sum[1],c[1]);
adder_1bit zz4(a[2],b[2],c[1],sum[2],c[2]);
adder_1bit zz5(a[3],b[3],c[2],sum[3],c[3]);
adder_1bit zz6(a[4],b[4],c[3],sum[4],cy);

endmodule

The 8 bit substractor is designed by module instantiation of 3 bit and 5 bit adder.

8-bit substractor:

module substractor(a,b,s,cy,SW1,SW2,SW3,SW4,SW5,SW6,SW7,SW8,SW9,SW10,SW11,SW12,SW13,SW14,SW15,SW16,LD0,LD1,LD2,LD3,LD4,LD5,LD6,LD7,LD15);
input wire [7:0]a,b;
output [7:0]s;
output cy;
output wire LD15;
assign a[0]=1;
input wire SW1,SW2,SW3,SW4,SW5,SW6,SW7,SW8,SW9,SW10,SW11,SW12,SW13,SW14,SW15,SW16;
output wire LD0,LD1,LD2,LD3,LD4,LD5,LD6,LD7;
wire c0,c1;
wire [7:0]b1;
assign SW1=a[0],SW2=a[1],SW3=a[2],SW4=a[3],SW5=a[4],SW6=a[5],SW7=a[6],SW8=a[7];
assign SW9=b[0],SW10=b[1],SW11=b[2],SW12=b[3],SW13=b[4],SW14=b[5],SW15=b[6],SW16=b[7];
assign b1=~b;
adder_3bit zzz2(a[2:0],b1[2:0],1,s[2:0],c0);   
adder_5bit zzz1(a[7:3],b1[7:3],c0,s[7:3],c1);
assign LD0=s[0],LD1=s[1],LD2=s[2],LD3=s[3],LD4=s[4],LD5=s[5],LD6=s[6],LD7=s[7];
assign cy=~c1;
assign LD15=cy;
endmodule

The output :

Add a comment
Know the answer?
Add Answer to:
Write an Verilog code for a 8-bit subtractor (Bits are in 1's complement) using the following:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please code the following in Verilog: Write the HDL gate-level hierarchical description of a four-bit adder-subtractor...

    Please code the following in Verilog: Write the HDL gate-level hierarchical description of a four-bit adder-subtractor for unsigned binary numbers similar to the following circuit. You can instantiate the four-bit full adder described in the following example code Figure 4.13a, 4-Bit adder-subtractor without overflow Inputs: 4-Bit A, 4-Bit B, and Mode M (0-add/1-subtract) Interfaces: Carry Bits C1, C2, C3 Outputs: Carry C (1 Bit, C4), Sum S (4 bit) Bo A FA FA FA FA module Add half (input a,...

  • 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.Condition...

    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...

  • Building and testing basic combinational circuits using Verilog HDL Description: Build and test t...

    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...

  • Construct the 8-bit ripple-carry adder/subtractor for signed integers. Negative numbers are in th...

    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...

  • Introduction: This experiment studies the design of an 8-bit adder/subtractor circuit using VHDL capture. The experiment...

    Introduction: This experiment studies the design of an 8-bit adder/subtractor circuit using VHDL capture. The experiment investigates the implementation of addition and subtraction operations with circuits. This lab uses the virtual simulation environment to validate the design practically in the FPGA board. Equipment: • This experiment requires Quartus Prime and the Intel's DE2-115 FPGA board. • All students should have the Intel QP and ModelSim-Intel-Starter-Edition softwares installed in personal computers. • VPN connection to UNB Network and remote desktop software...

  • Design an 8-bit full adder using Verilog (Use only 1-bit full adders). Write the design code,...

    Design an 8-bit full adder using Verilog (Use only 1-bit full adders). Write the design code, test-bench code of it, and test your design with six inputs. Note: Only use Verilog to design 8-bit full adder.

  • Please help to complete the code and write the testbench to design the following adder. 1.In...

    Please help to complete the code and write the testbench to design the following adder. 1.In this section, you add pipeline stage. 8 bits are used at every pipeline stage.Use the following template to complete your Verilog coding. // Addition of two 16 bit, 2's complement nos., n1 and n2. 8 bits addition at a time. Result is 17 bits. module adder_b (clk, n1, n2, sum) ; input clk ; input [15:0] n1 ; input [15:0] n2 ; output [16:0]...

  • Question: Part 1: In the second part of this lab, we will extend our adder to...

    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:...

  • Write a behavioral Verilog module for a 4-bit Johnson counter that has 8 states. The counter load...

    Write a behavioral Verilog module for a 4-bit Johnson counter that has 8 states. The counter loads the "0000" state if reset is low. The counter should start and end with this state. Write a testbench to verify the correctness of the 4-bit Johnson counter. The testbenclh should have a clock with a period of 20ns and a reset signal. The testbench should store the 4-bit binary outputs of the counter in a file, which will be used to provide...

  • Write a Verilog program to implement and test a subtractor. The program should have three modules....

    Write a Verilog program to implement and test a subtractor. The program should have three modules. The first module, called cfulladder implements a one bit subtractor with two 1-bit outputs, S and Cout, and three one bit inputs A, B, Cin. You have to use always keyword to implement this combinational circuit. The second module, called sub4 implements a four bit subtractor by instantiating 4 cfulladder modules. It has the same inputs and outputs but now the S, A, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT