EE434 ASIC & Digital Systems: Partha Pande School of EECS Washington State University Pande@eecs - Wsu.edu
EE434 ASIC & Digital Systems: Partha Pande School of EECS Washington State University Pande@eecs - Wsu.edu
Lecture 20
System Tasks and Functions
Built in tasks contained in a library
$display
System Tasks and Functions (cont’d)
$finish
$ monitor
The $monitor system task provides the ability to monitor and display the values of any
The $stop system task puts the simulator into a halt mode, issues an interactive command prompt
$time
The $time system function returns the current simulation time as a 64-bit integer. $time must be
used in an expression.
Test Benches
Module under test
module adder (a, b, y);
input [31 : 0] a, b;
output [31 : 0] y;
assign y = a + b;
endmodule;
Test Benches
module testbench ()
reg [31 : 0] testvectors [1000 : 0];
reg clk;
reg [10 : 0] vectornum, errors;
reg [31 : 0] a, b, expected_y;
wire [31 : 0] y;
always
begin
clk = 0; #50; clk = 1; #50;
end
Test Benches
//on each clock step, apply the test vector
always @ (vectornum)
begin
if (vectornum = = 100 || testvectors [vectornum] == 32 ‘bx)
begin
$display (“completed %d tests with %d errors.”, vectornum,
errors);
$finish;
end
end
endmodule
Synthesis Issues
Incorrect stimulus list
module incorrect_latch (input clk,
input [3 : 0] d,
output reg [3 : 0] q);
always @ (clk)
if (clk) q <= d;
endmodule
always @ (posedge s)
if (s) y <= d_1;
else y <= d_0;
endmodule
Instead of a MUX this circuit will behave as a flip-flop. At the positive edge of s it
endmodule OUT1
R CLR Q
STATE
EN SET
S Q
A
OUT2
R CLR Q
Undefined Outputs
always @ (*)
end A
CLR Q OUT 2
else begin
out2 <= 1;
out1 <= 0;
end
endmodule
Shorted Outputs
module mux_2 (input[3 : 0] d0, d1,
input s,
output [3 : 0] y); s
y
d1
Shorted Outputs
A reg is assigned in two different always blocks
always @(set)
if (set) q <= 1;
Comparisons
always @ (b)
begin
a = 1;
end
ALU
ALU computes a variety of logical and
arithmetic functions based on opcode.
May offer complete set of functions of two
variables or a subset.
ALU built around adder, since carry chain
determines delay.
ALU as multiplexer
Compute functions then select desired
one:
opcode
AND
OR
NOT
SUM
Verilog for ALU
‘define PLUS 0
‘define MINUS 1
‘define AND 2
‘define OR 3
‘define NOT 4
module alu(fcode,op0,op1,result,oflo);
parameter n=16, flen=3; input [flen-1:0] fcode; [n-1:0] op0, op1; output [n-1:0] result; output
oflo;
assign
{oflo,result} =
(fcode == ‘PLUS) ? (op0 + op1) :
(fcode == ‘MINUS) ? (op0 - op1) :
(fcode == ‘AND) ? (op0 & op1) :
(fcode == ‘OR) ? (op0 | op1) :
(fcode == ‘NOT) ? (~op0) : 0;
endmodule
Verilog for barrel shifter
module shifter (data, b ,result);
parameter Nminus1 = 31; /* 32-bit shifter */
input [Nminus1:0] data;
input [3:0] b; /* amount to shift */
output [Nminus1:0] result; /* shift result */
fulladd a0(a[0],b[0],carryin,sum[0],carry[1]);
fulladd a1(a[1],b[1],carry[1],sum[1],carry[2]);
…
fulladd a7(a[7],b[7],carry[7],sum[7],carryout]);
endmodule