Aula14 Verilog
Aula14 Verilog
Verilog
Purpose of HDL:
1. Describe the circuit in algorithmic level
(like c) and in gate-level (e.g. And
gate)
2. Simulation
3. Synthesis
1
29/4/2010
Port List
Port Declaration
2
29/4/2010
Operators Operators
reg [3:0] a, b, c, d; Reduction Operators: module sample (a, b, c, d);
Arithmetic: wire[7:0] x,y,z;
input [2:0] a, b;
*,+,-, /,% Unary operations returns single-bit values
parameter n =4; output [2;0] c, d;
• & : and
Relational • | :or
wire z,y;
<,<=,>,>=,==, != c = a + b; • ~& : nand
assign z = ~| a;
Bit-wise Operators d = a *n; • ~| : nor
c = a * b;
• ^ : xor
• Not: ~ • ~^ :xnor
If(a==b) d = 1; else d =0;
• XOR: ^ If(x==y) d = 1; else d =0;
Shift Operators d = a ~^ b;
• And : & 5’b11001 & 5’b01101 ==> 5’b01001
Shift Left: <<
• OR: | d = a ~^ b;
Shift right: >> if ((a>=b) && (z)) y=1;
• XNOR: ~^ or ^~ Concatenation Operator else y = !x;
if ((x>=y) && (z)) a=1;
Logical Operators else a = !x;
{ } (concatenation)
Returns 1or 0, treats all nonzero as 1 { n{item} } (n fold replication of an item) assign d << 2; //shift left twice
Conditional Operator assign {carry, d} = a + b;
• ! : Not
assign c = {2{carry},2{1’b0}};
• && : AND 27 && -3 ==> 1 Implements if-then-else statement
// c = {carry,carry,0,0}
• || : OR (cond) ? (result if cond true) : (result if cond false)
assign c= (inc==2)? a+1:a-1;
endmodule
3
29/4/2010
Blocking Vs Non-Blocking
Initial
begin
#1 e=2;
#1 b=1;
#1 b<=0;
e<=b; // grabbed the old b
f=e; // used old e=2, did not wait
e<=b