TESTBENCH HELP You must test all the opCodes Test when in1 i

TESTBENCH HELP:

You must test all the opCodes. Test when in1 is positive and when it is negative, and when in2 is positive and when it is negative. Test values that produce overflow, and also values that don\'t produce overflow. Also, pay attention to interesting values, like border (or corner) cases, like: 32767, 32766, 1, 0, -1, -32767, -32768.

REQUIRED: 26 test cases covering these scenarios:

one test case for each bitwise operation:

AND

OR

XOR

One\'s complement of in1

two test cases (one not producing overflow and another producing overflow) for each of the operations of:

increment,

decrement

divide

four test cases for multiplication:

one not producing overflow when in1 is positive

one not producing overflow when in1 is negative,

one producing overflow when the result is too positive

one producing overflow when the result is too negative

six test cases for addition:two test cases that produce overflow:

one producing overflow when the result is too positive

one producing overflow when the result is too negative

four test cases that don\'t produce overflow:

one where in1 is positive and in2 is positive

one where in1 is positive and in2 is negative

one where in1 is negative and in2 is positive

one where in1 is negative and in2 is negative

six test cases for subtraction:two test cases that produce overflow:

one producing overflow when the result is too positive

one producing overflow when the result is too negative

four test cases that don\'t produce overflow:

one where in1 is positive and in2 is positive

one where in1 is positive and in2 is negative

one where in1 is negative and in2 is positive

one where in1 is negative and in2 is negative

Please remember that you need to add some wait time in nanoseconds (for example: \"#100;\") between each test case. Because that statement simulates a wait period of time in nanoseconds in which the values of in1, in2 and opCode won\'t change, they will hold whatever value you just assigned to them. Remember you learned that hardware circuits have delays from the time the inputs are given until the time the output is being produced, so Verilog simulates that. If you don\'t add that wait time, the values of in1, in2 and opCode will change so quickly that you won\'t allow enough time for your implementation to produce an output. So you will only be able to see the output of the last test case.

Include in your test bench a $monitor statement in order to keep track and print in console changes in the inputs and outputs. Alternatively you could have $display statements instead. For example:

$monitor(\"opCode( %b ), in1( %d ), in2( %d ), result( %d ), overflow( %b )\", opCode, in1, in2, result, overflow);

PROBLEM TESTED ****only for reference; testbench is the only thing needed****

Build a Verilog module named \"calculator\" that takes in two signed 16-bit numbers named \"in1\" and \"in2\" and performs the following functions depending on the value of another 4-bit input named \"opCode\" (see table below). Be aware that the opCode is not signed. The outputs of the module \"calculator\" must be a signed 16-bit number named \"result\", and a 1-bit \"overflow\". Be aware that the value of \"overflow\" doesn\'t always get calculated the same way, it depends on the operation (see table below for more info and examples). The value of the output \"overflow\" will be one if an overflow occurred or the value of \"result\" is not completely accurate or correct; else the output \"overflow\" will be zero.

The syntax to declare buses as signed is:
input signed [15:0] in1;
output reg signed [15:0] result;
//Declaring outputs as \"reg\" will allow you to assign values to them

Also, be aware that unsigned N-bit registers (like the inputs A and B in project 2) can store values from 0 to 2N-1. While signed N-bit registers can store values from -2N-1 to 2N-1-1, where N is the number of bits of the register.

opCode Operation that has to be performed
0000 Add both inputs. Be aware that the overflow detection when adding and subtracting must be different than for Project 2 because in Project 2 the inputs were unsigned, while now for Project 3 the inputs are signed.
0001 Subtract in1 - in2.
0010 Multiply in1 by five
0011 Divide in1 by ten. When dividing by ten, signal an overflow when in1 is not exactly divisible by ten. For instance, if in1=30, then result=3 and overflow=0; but if in1=35, then result=3 and overflow=1. You will need to explore the use of the percentage sign (%), which performs modulo operations (also known as \"modulus operator\", https://en.wikipedia.org/wiki/Modulo_operation ). The modulo finds the remainder of a division. If the remainder is zero then overflow=0; but if the remainder is not zero then produce overflow =1.
0100 Bitwise AND. Even though in1, in2 and result are declared as signed numbers, when applying the bitwise operations they are taken as raw bits. A bitwise operation (https://en.wikipedia.org/wiki/Bitwise_operation ) is when the operation is applied to the individual bits. In this case, there will be an AND gate operation between the individual bits of in1 and the individual bits of in2; such that an AND logic will be applied to the first bit of in1 and the first bit of in2 and the output of that AND will be the first bit of result; an AND logic will be applied to the bit of position n of in1 and the bit of position n of in2 and the output of that AND will be the bit of position n of result; and so on.
For example:
in1 = 1010110011110000
in2 = 1100101000110011
result = 1000100000110000
Bitwise AND, XOR and OR operations can\'t overflow, so overflow=0 by default.
0101 Bitwise XOR. Similar to explanation above, but with an XOR (also known as exclusive OR) operation instead.
Example:
in1 = 1010110011110000
in2 = 1100101000110011
result = 0110011011000011
0110 Bitwise OR. Similar to explanation above, but with an OR operation instead.
Example:
in1 = 1010110011110000
in2 = 1100101000110011
result = 1110111011110011
0111 One\'s Complement of in1. Perform one\'s complement, by inverting bits (do not add one afterwards, because that would be two\'s complement). Complement operation can\'t overflow, so overflow=0 by default.
Examples:
in1=\'b00000000000000; opCode=\'b0111; expectedOverflow=\'b0; result=\'b1111111111111111;

in1=\'b0000000000000001; opCode=\'b0111; expectedOverflow=\'b0; result=\'b1111111111111110;
1000 Increment in1 by 1.
Examples:
if in1=3, then result =4.
if in1=-3, then result =-2.
1001 Decrement in1 by 1.
Examples:
if in1=3, then result =2
if in1=-3, then result =-4.

Solution

ANSWER:

The question mentions that 26 test cases are required. So, you could have every single testcase in a different testbench file an simulate them one by one. Or, you could also have all the 26 different scenarios in the same initial block and simulate at one shot. I prefer the second approach and have used the same to answer your question.

module testbench;

wire [15:0] in1_tb, in2_tb, result_tb;

wire [3:0] op_tb;

wire overflow_tb;

//Arrays which have the stimulus

wire [15:0] in1 [26], in2 [26];

wire [3:0] op[26];

//Creating first set of stimuli

assign in1 [0] = 16\'h1234;

assign in2 [0] = 16\'h2340;

assign op [0] = 4\'hA;

Similarly create all stimuli by extending this array.

//Design instantiation

calcuator RTL (

.in1 (in1_tb),

.in2 (in2_tb),

.op (op_tb),

.out (out_tb),

.overflow (overflow_tb));

//Stimulus:

initial begin

$monitor(\"Opcode - %b, in1 - %h, in2 - %h, out - %h, overflow - %b \", op_tb, in1_tb, in2_tb, out_tb, overflow_tb);

for (i=0;i<26;i++) begin

inp1_tb = inp1[i];

inp2_tb = inp2[i];

op_tb = op[i];

#100;

end

end

endmodule

PS: I hope I have cleared your problem. If you have any questions, feel free to ask me.

TESTBENCH HELP: You must test all the opCodes. Test when in1 is positive and when it is negative, and when in2 is positive and when it is negative. Test values
TESTBENCH HELP: You must test all the opCodes. Test when in1 is positive and when it is negative, and when in2 is positive and when it is negative. Test values
TESTBENCH HELP: You must test all the opCodes. Test when in1 is positive and when it is negative, and when in2 is positive and when it is negative. Test values
TESTBENCH HELP: You must test all the opCodes. Test when in1 is positive and when it is negative, and when in2 is positive and when it is negative. Test values

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site