Drill 4 Soquiat Marc Hendri
Drill 4 Soquiat Marc Hendri
Drill 4 Soquiat Marc Hendri
SCHOOL OF EE-ECE-CpE
User-Defined Primitives
DRILL 4
The logic gates used in HDL descriptions with keywords and, or, etc. are defined by
the system and are referred to as system primitives. The user can create additional
primitives by defining them in a tabular form. These types of circuits are referred to
as user-defined primitives (UDPs). One way of specifying a digital circuit in tabular
from is by means of a truth table.
1. Combinational UDP
• This table specifies the various input combinations and their
corresponding output values. Any combination that is not specified is
an x for the output.
2. Sequential UDP
• The internal state is described using a 1-bit register.
• It uses the current value of the register and the input values to
determine the next value of the register.
2
• Its model requires that its output be declared as reg data type, and
that column be added to the truth table to describe the next state.
So the columns are organized as: inputs: state:
next state
Symbol Meaning
0 logic 0
1 logic 1
x unknown
? any of 0, 1, or x
b any of 0 or 1
- no change
(AB) value change from A to B
* same as (??)
r same as (01)
f same as (10)
p any of (01), (0x), (x1)
n any of (10), (1x), (x0)
module testprimitive1;
reg A, B, C;
wire X;
Majority3 (X,A,B,C);
initial begin
A=1'b0;B=1'b0;C=1'b0;
$display(" A B C X");
$monitor(" %b %b %b %b",A,B,C,X);
#2 A=1'b0; B=1'b0; C=1'b0;
#2 A=1'b0; B=1'b0; C=1'b1;
#2 A=1'b0; B=1'b1; C=1'b0;
#2 A=1'b0; B=1'b1; C=1'b1;
4
#2 A=1'b1; B=1'b0; C=1'b0;
#2 A=1'b1; B=1'b0; C=1'b1;
#2 A=1'b1; B=1'b1; C=1'b0;
#2 A=1'b1; B=1'b1; C=1'b1;
#2 $finish;
end endmodule
The table below shows an example of sequential UDP. Simulate the program;
save it as drill4_2.vl
initial F=0;
table
// CLK T : F(STATE) : F(NEXT)
(01) ? : x : 0 ;
(01) 0 : 0 : 0 ; (01)
0 : 1 : 1 ; (01)
1 : 0 : 1 ; (01) 1
: 1 : 0 ; (10) ? :
x : 0 ; (10) 0 : 0
: 0 ; (10) 0 : 1
: 1 ; (10) 1 : 0 :
0 ;
(10) 1 : 1 : 1 ;
endtable
endprimitive
module pri;
5
reg x, clk;
wire y;
always #1 clk=!clk;
initial begin
x=0; #4
x=1;
repeat(8)
#8 x=~x; end
initial begin
$display(" TIME clk T Q");
$monitor($time,,," %b %b %b ",clk, x, y);
#16 $finish; end
endmodule
7
INTERPRETATION OF RESULTS
In this experiment, we focus on User-Defined Primitives. These are
additional primitives added to the system by the users. In this activity, we are
tasked to choose one programming exercise. The choices were creating a
combinational UDP of 8x1 demultiplexer or a combinational UDP of a binary
subtractor. I choose the combinational UDP of a binary subtractor. After coding,
you can see in the provided screenshots in the folder the output of the program
(truth table) together with the timing diagram. In the truth table, A, B, and Bin are
the input of the operation providing with 8 different combinations. Diff is the
difference output with consideration of the borrow input (Bin). Lastly, Bout
represents the borrow output. It indicates whether a borrow occurred during the
operation.
8
RESULTS AND CONCLUSION
In this experiment, we learned about User-Defined Primitives and its
guidelines and types of behavior it can define. We learned that a UDP starts with a
keyword primitive and ends with the keyword endprimitive. The table inside the
primitive should be defined by the table keywords and ends with an endtable
keyword. These are just some of the rules in using UDP. For the programing exercise
done in this laboratory experiment, we utilize defining the Combinational behavior
of a circuit. In a combinational UDP, various input combinations are specified with
correspondence to their outputs as per observed in the finished activity. Overall,
the logic gates used in HDL are already defined in the system, it is within the user
that they add other primitives in the system.