Question

Write a Verilog module and testbench for a 3:1 multiplexer that implements the following function. You...

  1. Write a Verilog module and testbench for a 3:1 multiplexer that implements the following function. You can use “case”, “if” or “assign” statements. Grades will be agnostic of your style of implementation (you can choose any of these three styles) and only on the correct functionality.

Y = S0’S1’D0 + S0S1’D1+ S1D2

Here, S0 and S1 are the two select signals and D0, D1 and D2 are the three data signals.

  1. What does the following snippet of Verilog code do? Can you name the functionality that’s being represented by this? Rewrite the same functionality using case statements.

always @(A)

begin

Test=8’b00000001;

Y=3’bx;

for (N=0; N< 8; N=N+1)

begin

if(A==Test)

Y=N;

Test=Test<<1;

                                                end

                        end

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

1.Verilog code:

module mod(s0,s1,d0,d1,d2,y);
input s0,s1,d0,d1,d2;
output reg y;

always@(s0,s1)
begin

if(s1==1)
y=d2;
else if (s0==0&&s1==0)
y=d0;
else if(s0==0&&s1==1)
y=d1;

end
endmodule

module tb;
reg rs0,rs1,rd0,rd1,rd2;
wire wy;

mod m1(rs0,rs1,rd0,rd1,rd2,wy);

initial
begin
rs0=0;
rs1=0;
rd0=1;
#5 $display("s0=0 and s1=0 then y->%d",wy);
rs0=1;
rs1=0;
rd1=1;
#5 $display("s0=1 and s1=0 then y->%d",wy);
rs0=1;
rs1=1;
rd2=1;
#5 $display("s1=1 then y->%d",wy);
rs0=0;
rs1=1;
rd2=1;
#5 $display("s1=1 then y->%d",wy);
end
endmodule

Output:

2) given verilog code acting as 8*3 encoder

Vrilog cod using case:

module mod(a,y);
input[7:0] a;
output reg[3:0] y;
always@(a)
begin
case(a)
8'b00000001: y=0;
8'b00000010: y=1;
8'b00000100: y=2;
8'b00001000: y=3;
8'b00010000: y=4;
8'b00100000: y=5;
8'b01000000: y=6;
8'b10000000: y=7;
endcase
end
endmodule


module tb;
reg[7:0] ra;
wire[3:0] wy;

mod ma(ra,wy);

initial
begin
ra=8'b00000001;
#5 $display("%b",wy);
ra=8'b00000010;
#5 $display("%b",wy);
end
endmodule

Output:

Add a comment
Know the answer?
Add Answer to:
Write a Verilog module and testbench for a 3:1 multiplexer that implements the following function. You...
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
  • 1) Implement the function given below using each of the following methods: ?(?, ?, ?, ?)...

    1) Implement the function given below using each of the following methods: ?(?, ?, ?, ?) = P (0,1,3,4,7,9,13,15) ∙ ?(5,14) As few 16-1 multiplexers as possible. One 8-1 multiplexer, inverters, and a few 2-1 multiplexers. One 4-1 multiplexer and a few 2-1 multiplexers As few 2-1 multiplexers and inverters as possible. 2) Write a Verilog module and testbench for a 3:1 multiplexer that implements the following function. You can use “case”, “if” or “assign” statements. Grades will be agnostic...

  • a) Write a Verilog module that implements a 1-bit partial full adder (PFA). b) Through instantiating...

    a) Write a Verilog module that implements a 1-bit partial full adder (PFA). b) Through instantiating the module in a) plus other logic, implement a 4-bit full adder with Verilog. c) Write a proper test-bench and stimulus, thoroughly test your 4 bit carry lookahead adder. d) Show a waveform snapshot that indicates you adder can correctly compute 0101 + 1101 and show your results.

  • I need help writing a test bench for the following Verilog code module CU(IE, WE, WA,...

    I need help writing a test bench for the following Verilog code module CU(IE, WE, WA, RAE, RAA, RBE, RBA, ALU,                SH, OE, start, clk, reset, Ng5); //nG5 denotes (N>5);    input start, clk, reset;    output IE, WE, RAE, RBE, OE;    output [1:0] WA, RAA, RBA, SH;    output [2:0] ALU;       input wire Ng5;    reg [1:0] state;    reg [1:0] nextstate;    parameter S0 = 3'b000;    parameter S1 = 3'b001;...

  • 3. Now let’s look at the Verilog implementation of the arbiter state machine. [Normally we would include an always block...

    3. Now let’s look at the Verilog implementation of the arbiter state machine. [Normally we would include an always block for the state update but we’re not going to bother with that here.] (a) Define the module interface and the state variables you will use. Also use a parameter statement so that you can use labels for your states. Remember to define the output signals as type reg, since you will be assigning to them inside the case statement, which...

  • A sequential circuit has one input (X), a clock input (CLK), and two outputs (S and...

    A sequential circuit has one input (X), a clock input (CLK), and two outputs (S and V). X, S and V are all one-bit signals. X represents a 4-bit binary number N, which is input least significant bit first. S represents a 4-bit binary number equal to N + 3, which is output least significant bit first. At the time the fourth input occurs, V = 1 if N + 3 is too large to be represented by 4 bits;...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • 3) Out of the following, name which kind of attack you carried out in part 1...

    3) Out of the following, name which kind of attack you carried out in part 1 and part2: a. ciphertext only, b. known plaintext, c. chosen plaintext, d. chosen ciphertext. Explain your answer Problem 3 10 points] A 4-bit long message was encrypted using one-time pad to yield a cipher-text “1010” Assuming the message space consists of all 4-bit long messages, what is the probability that the corresponding plaintext was “1001”? Explain your answer. Problem 4 Assume we perform a...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • In problem 3, you will write a function, findvertically (), which will determine whether or not...

    In problem 3, you will write a function, findvertically (), which will determine whether or not a given word exists in a word search puzzle vertically. In word search puzzles, words can be written upwards or downwards. For example, "BEAK" appears at [1] [3] written downwards, while "BET" appears at [2] [2] written upwards: [["C", "A", "T", "X", "R"], ["D", "T", "E", "B", "L"], ["A" "R" "B", "E", "Z"], ["X", "O", "E", "A", "U"], ["J", "S", "O", "K", "W"]] Your...

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