Anda di halaman 1dari 23

EEE348/3 Introduction to

Integrated Circuit Design


Verilog - Behavioral based
Description : Continuous
Assignment
Dr. Bakhtiar Affendi Bin Rosdi
eebakhtiar@usm.my
Ext : 6083
Room No. : 4.09
Module internals
Internals of each module
Can be described based on
Structural : Function is performed by connections of
components
Connection of instances
Connection of primitive gates
Behavioral : What the circuit will do, not how to
build it in h/ware
Continuous Assignment (assign statement)
Procedural Constructs (always, initial block)

Can mix structural and behavioral


Continuous Assignment
Continuous assignments
most basic statement in behavioral
used to drive a value onto a net
starts with keyword assign
Ex : assign out = ini & in2;
have following characteristics :-
left hand side must be net (wire)
cannot be a register
operands on right hand side can be
register or net
always active, expression is evaluated
as soon as one of the right hand side
operands changes
value is assigned to left hand side
statements are executed concurrently
Expressions, operators and Operands
in gate level, primitive gates are used to
describe a circuit
in continuous assignments, to describe a circuit,
used:-
expressions
operands
operators
Expressions
constructs that combine operators and
operands to produce result
examples

aAb
addr1[20:17] + addr2[20:17]
ini | in2
Operands
any one of the data types:-
integers, real, registers, nets, times
examples :-
integer count, finalcount;

finalcount = count + 1; // count is an integer operand

real a, b, c;
c = a - b; // a and b are real operands

reg [15:0] reg1, reg2;


reg [3:0] regout;
reg out = reg1[3:0] A reg2[3:0]; // regl and reg2 are reg operands
Operators
act on operands to produce results
examples

d1 && d2 // && is an operator on operands d1 and d2

!a[0] //! is an operator on operand a[0]

B >> 1 // >> is an operator on operands B and 1


Type of operators
many types of operators
arithmetic, logical, relational, equality,
bitwise, reduction, shift, concatenation,
replication, conditional
each operator is denoted by a symbol
the operators also can be used in behavioral
statement

* Can be used in procedural constructs too


Arithmetic operators
two types binary and unary
binary :- multiply (*), divide (/), add (+),
subtract (-), power (**), modulus (%)
take two operands
if any operand bit is x, the result is x

unary :- + and -, used to specify positive or


negative sign of the operand
advisable to use negative number in
real
and integer only
negative number represented as 2s
complement internally
Example : Arithmetic operators

4'b0011 * 4'b0100 //result is 4b1100


4'b0011 +4'b0100 //result is 4b0111
4'b0100 - 4'b0011 //result is 4b0001
7/2 // result is 3, truncates any fractional part
7%2 // result is 1
7 ** 2 // result is 49
4'b000x + 4'b0011 //result is 4 bxxxx
Logical operators
two types binary and unary
binary :- and (&&), or (||)
unary :- not (!)
always evaluate to a 1-bit value (0, 1 or x)
if operand is not equal to 0, equivalent to 1
if operand is x or z, equivalent to x
to group logical operators
use of parentheses is highly recommended
3 && 0 // result is 0
3 || 0 // result is 1
!3 // result is 0
!0 // result is 1
2bx0 && 2'b11 // result is x
Relational operators
greater-than (>), less-than (<)
greater-than-or-equal-to (>=), less-than-or-equal-to (<=)
If used in expression
returns 1 if expression is true
returns 0 if expression is false
returns x if any x or z in the operands

4 < = 3 // result is 0
4 > 3 // result is 1
2blx >= 2bll // result is x
Equality operators
logical-equality (==), logical-inequality (!=)
case-equality (===), case-in-equality (!==)
comparison is bit by bit
zero filling if unequal length
If used in expression
returns 1 if expression is true
returns 0 if expression is false
for (==) and (!=), returns x if x or z in operand
for (===) and (!==), only returns 1 or 0
4 == 3 // result is 0
4b1010 != 4b1101 // result is 1
4b101x == 4b101x // result is x
4b101x === 4b101x // result is 1
4b101z != 4b101z//result isx
4b101z !== 4b101z // result is 0
Bitwise operators
negation (~), and (&), or (|), xor (A), xnor (A~, ~A)
comparison is bit by bit
zero filling if unequal length
z is treated as x

~(4b1010) //result is 4b0101


(4b1010)&(4b1101) // result is 4b1000
(2b10)\(4b1101) //result is 4b1111
(2b1x)A(2bx1) // result is 2bxx
(4b0111)A~(2b1x) // result is 4 b101x
Reduction operators
and (&), nand (~&), or (|), nor (~|), xor (A), xnor (~A, A~)
nand (invert and), nor (invert or), xnor (invert xor)
take only one operand
perform bitwise operation on a single vector
yield 1-bit result

& 4'b1001 // result is 0


4'b1001 //result is 1
& 4b1x01 // result is 0
\ 4'b1001 //result is 1
~\ 4'b1001 //result is 0
A 4'b1001 //result is 0

4'b1001 //result is 1
Shift operators
right shift (>>), left shift (<<)
shift a vector operand by specified number of bits
the vacant bit positions are filled with zeros
shift operations do not wrap around

4'b1001 >> 1 // result is 4b0100


4'b1001 << 1 // result is 4b0010
4'b1001 >> 2 //result is 4b0010
4'b1001 << 2 //result is 4b0100
Concatenation operator
mechanism to append multiple operands
the operands must be sized
unsized operands are not allowed

{1b1, 2b01} // result is 3b101


{2b11, 2b01, 1b1} // result is 3 b11011
Replication operator
used to replicate a group of bits n times

{2{2b10}} // result is 4b1010


Conditional operator
takes three operands
condition_expr ? true_expr : false_expr;
condition expr is first evaluated
If the result is true (logical 1)
then true_expr is evaluated
If the result is false (logical 0)
then false_expr is evaluated
similar to a multiplexer
frequently used in dataflow modeling to model
conditional assignments
can be nested

assign out = sel ? a : b;


Example 1 : 1-bit Half Adder
Design a 1-bit Half adder based on continuous assignment

> cout
a >

HA > sum
b >

Boolean expression Arithmetic Operator

module half_adder(c,s,a, b); module half_adder(c,s,a,b);


input a, b; input a, b;
output c, s; output c, s;
assign { c , s} = a + b;
assign s = ~a&b | a&^b ;
assign c = a&b ; endmodule

endmodule
Example 2 : 1-bit Full Adder

Design a 1-bit Full adder based on continuous assignment
c n

> cout
a >
> FA > sum
b

Boolean expression Arithmetic Operator

module full_adder(c, s, a, b, cin); module full_adder(c, s, a, b, cin);


output c, s; output c, s;
input a , b, cin;
input a , b, cin;
assign s = aAbAcin;
assign c = (a&b) | ( (a^b)&cin); assign {c, s} = a + b + cin;
endmodule endmodule
Example 3 : 2-1 Mux
Design a 2-1 Multiplexer based on continuous assignment

Boolean expression Conditional Operator


module mux2_l(out, a, b, s) ; module mux2_l(out, a, b, s);
output out; output out;
input a, b, s; input a, b, s;
assign out = (a&s) | (b&~s); assign out = s? a: b;
endmodule
endmodule

Anda mungkin juga menyukai