SlideShare a Scribd company logo
1 of 73
Download to read offline
Verilog HDL Basics
What we already learned
 Verilog can model: behavioral, RTL structure
 Module: basic unit in Verilog
 A tutorial: Module instantiation, stimulus, respone
 Procedure block: initial, always
Verilog HDL Basics


  Basic Element and Data Type
4 Vaules Logic System
Module
Moudle Port Mapping
 In   Order
  − counter dut (count, clk, reset);

 By   Name
  − counter dut (.count(count), .clk(clk), .reset(reset));
Comment and White Space
module MUX2_1 (out, sel, inb, ina);
// Port declarations, single line comments         space, tab,
                                                   and newline
    output out;
    input sel, inb, ina; // terminated with ;      CASE Sensitive
/* multiple lines comments
    The netlist logic selects input quot;inaquot; when
    sel is 0 and it selects ”inb” when sel is 1.
*/
    not (sel_, sel);
    and (sela, ina, sel_),
    (selb, inb, sel );
    or (out, sela, selb);
endmodule
Identifiers and Keywords

Identifier:
  Names of instances, modules, nets, ports, and variables
Keyword:
   Language construct, lower case

module MUX2_1 (out,sel,inb,ina);
  output out;                            // names you provide such
    as
  input sel,inb,ina;            // ina, inb, sel, sel_, sela, selb, out,
  not (sel_, sel);              // and MUX2_1 are identifiers.
  and (sela, ina, sel_),
  (selb, inb, sel );
Module ports




               // input [msb:lsb] list_of_port_identifier
Data Type


                                 Devices/Blocks




                Storage




  Module parameters -Configure module
instances
Net
 Nets   are continuously driven by the devices that
  drive them. Ex, module or gate instantiation
 Continuous assignments, primitives, and registers
  can drive nets.
 Initial default value “z”
Types of Net




Examples           // bit select
wire [7:0] out ;   assign out[1]    =0
tri enable;        // part-select
wire a, b, c;
Logic Conflicts




 Always be cautious about 『 multiple driver 』 on a net.
Register
A  register maintains its value between discrete
  assignments.
 assignments to registers in procedural code
  blocks, task or function.
 Can't be output of “assign” statement.
 Doesn't imply a storage element in the hardware.
 Initial default value “x”
Type of Register




Examples:
reg            a;          // single bit
reg [3:0] b;         // 4 bits
reg [7:0]      c, d; // two 8bits regs
Parameters
 Use module parameters to configure module
 instances: parameter list_of_assignments
  − A parameter is an un-typed constant
  − You can use a parameter anywhere that you can use a
    constant or liter
Correct Data Type
Number
  [[<size>]’<radix>]<value>

   − size is the size in bits
   − B or B (binary), o or O (octal), d or D (decimal), h or H (hexadecimal)
 Examples
   12                  unsized decimal (extended to 32 bits with quot;0quot;)
   'H83a               unsized hexadecimal (extended to 32 bits with quot;0quot;)
   8'b1100_0001        8-bit binary, _ for readability
   8'h61               8-bit hex
   64'hff01            64-bit hexadecimal (extended to 64 bits with quot;0quot;)
   16'h456a            16-bit hex
   9'O17               9-bit octal
   32'bz01x            extended to 32 bits with quot;zquot;
   3’b1010_1101        3-bit number, truncated to 3’b101
   6.3                 decimal notation
   32e-4               scientific notation for 0.0032
   4.1E3               scientific notation for 4100
String
 string   constants, but has no explicit string data
  type.
 Store ASCII character strings in a reg array
 Example:
  − $monitor(quot;This string formats a value: %bquot;, monitored_object);



                                                  integer kkk;
                                                  kkk = $fopen(file);
Compiler Directives
`define      Define a text replacement macro
`ifdef       Conditionally compile source code,
`else        dependent upon which text macros
`endif       are defined
`include     Include a file of source code
`resetall    Reset all compiler directives
`timescale   Establish a simulation timescale
`undef       Undefine a text replacement macro
timescale
`timescale 1ns/100ps      //time_unit, time_precision
 Place the directive outside of a module definition
  seconds (s), milliseconds (ms), microseconds (us), nanoseconds (ns),

  picoseconds (ps), or femtoseconds (fs)
 to advance 1 ns simulation time
   `timescale 1 ns / 100 ps
      10 steps
   `timescale 1 ns / 1 ps
      1000 steps

Delays are multiples of time_unit
rounded to time_precision.
`timescale 10ns/1ns
#1.55 a = b;
'a' gets 'b' after 16 ns because
10ns*1.55 = 15.5 ns = 16ns rounded to nearest 1ns
Memory: array of registers
    reg [MSB:LSB] memory_name [first_addr:last_addr];



    reg [31:0] video_ram [0:7]
    // 8 words by 32 bit wide memory
    parameter wordsize = 16;
    parameter memsize = 1024;
    reg [wordsize-1:0] mem [0:memsize-1];
    // arrays of integer and time data types:
    integer int_array [0:1]; // array of 2 integer variables
    time time_array [8:1]; // array of 8 time variables
                            // the 3rd
    video_ram[2] = 1;
    $display(“video_ram[2] = %h”, video_ram[2]);

    // bit select not allowed for reg array
Verilog Primitives
Scope and Reference



                                        dut
      Module test_bench;
                                          Module ALU


                                                aa
      $monitor($time,quot;wire in A =%bquot;,
      dut.aa.a_in);
                                                       Module A
                                                       wire a_in


                                                bb


                                                       Module B
LAB
Verilog HDL Basics


  Simulator, IO
Event-Driven Simulation
 The   simulation scheduler
  − keeps track of when events occur, communicates events to
    appropriate parts of the model,
  − executes the model of those parts, and
  − as a result, possibly schedules more events for a future time.
  − Event-based simulation algorithms process only the changes in
    circuit state.
  − it maintains “simulated time” (sometimes “virtual time”) and the
    event list.
  − The simulation propagates values forward, through the circuit, in
    response to input pin events or autonomous event generators
    (such as clocks).
Event-Driven Simulation
 The simulator creates the initial queues upon
  compiling the data structures
 The simulator processes all events on the current
  queue, then advances
 The simulator moves forward through time, never
  backward
 A simulation time queue represents concurrent
  hardware events
System Tasks and Functions

 names start with a dollar sign ($) character
 Commonly used: Simulation Control, Display, File
 Example
    $display       $display(quot;out=%bquot;,out); // Display argument values
    $finish        $finish;                 // Terminate the simulation
    $monitor       $monitor($time,sel,a,b,out); // Monitor signal changes
    $stop          $stop;                  // Suspend the simulation
    $time          time_var = $time;       // Get the simulation time


    Check doc see ModelSim support

    <install_dir>docspdfoem_man.pdf
    chap5
    But... what is %b.......

IO Format Specifier




 escape




$monitor ($time, quot;%b t %h t %d t %oquot;, sig1, sig2, sig3, sig4);

$display(quot;Hello World, count = %d quot;, count ); // new line added
$write(quot;Hello World, count = %d nquot;, count ); // need escape
Verilog HDL Basics


  Operator
Operator: Arithmetic
Operator: Arithmetic Example
    Integer division discards any remainder

    A modulus operation retains the sign of the first operand

    The integer register data type is signed.

    The reg and time register data types are unsigned




reg [3:0] A, B; wire [4:0] sum, diff1, diff2, neg
assign sum = A+B; assign diff1 = A-B; assign diff2 = B-A; assign neg = -A;
$display(“%d %d %d %d %d %d”, A, B, sum, diff1, diff2, neg);
$display(“%b %b %b %b %b %b”, A, B, sum, diff1, diff2, neg);
-------------------------------------------------------------
A          B        A+B        A-B               B-A       -A        Stored in 2's
                                                                     complement
5          2        7          3                 29        27      but .....unsigned.
0101       0010 00111 00011                      11101 11011
                                                                    If result is same size
                                                                    carry lost
Operator: Bit Wise




            module bitwise_xor (y, a, b);
            input [7:0] a,b;
            output [7:0] y;
            assign y= a ^ b;
            //(0101_0101)^(0011_0000) = 0110_0101
Operators: Unary Reduction
Operator: Logic




reg [3:0] A, B
1. if (!A)      // false if all of its bits are 0
   if (A)      // true if any of its bits are 1
Operator: Equality
Operator: Relational
Operators: Shift




result = (start << 1);    // right operand treated as unsigned
                         // so always use positive number
Operator: Conditional


 if (conditional_expression)
      LHS = true_expression;
 else
      LHS = false_expression;quot;




                                 module mux41(O,S,A,B,C,D);
module driver(O,I,E);
                                 output O;
output O; input I,E;
                                 input A,B,C,D; input [1:0] S;
assign O = E ? I : 'bz;
                                 assign O =     (S == 2'h0) ? A :
endmodule
                                            (S == 2'h1) ? B :
                                            (S == 2'h2) ? C : D;
                                 endmodule
Operator: Concatenation
Operator: Replication
Operator Precedence
                      Highest




                      Lowest
Verilog HDL Basics


  Assignment, timing control
Sequential and Concurrent
Blocks
Continuous Assignment
Example
    Use continuous assignments outside of a procedural block



Delay
               wire #5 eq = (a == b);



Conditional
forece..release
 Apply  to net as well as reg
 Primarily used in testbench
 force sig_a = 1;
 release sig_a = 0;
Procedure Assignment
Initial Bloclk
Always Block
Example#1
            To reg
Example #2

                       When to start
                        this block




                Cout = ( a & b)            |
                       ( a & !b &cin)      |
                       (              );
   Sequential
Procedural Timing Control: #
 #0 IN1=0;IN2=1; // t=0
 #100 IN3=1;     // t=100
 #100 IN4=1      // t=200
Procedural Timing Control: @


                                                    Sensitivity List
                                             happened when signal transition




                                                  Clock qualifier
                                          posedge, negedge




       ?? non-blocking assignment, later in this section
Procedural Timing Control:
wait




                 // suspend here
                 // until (ack || rst) true
Missing Timing Control




A zero-delay behavioral loop is a common coding error.
In a zero-delay loop, the simulator continuously adds events to the
same queue. As the queue never empties, the simulator appears to
hang
Timing Control Examples
Blocking and Nonblocking
Example
    Initial                               Initial
    begin                                 begin
        A=1;                                  A=1;
        B=0;                                  B=0;
        ....                                  ....
        A=B; // Uses B=0                      A<=B; // Uses B=0
        B=A; // Uses A=0                      B<=A; // Uses A=1
        end                                   end
        // A=0                                // A=0
        // B=0                                // B=1
    The simulator completes a            The simulator completes a nonblocking
                                    
                                         assignment (<=) in two passes: It
    blocking assignment (=) in one
                                         evaluates the RHS expression and
    pass: It evaluates the RHS
                                         schedules the LHS assignment. It
    expression and stores the
                                         updates the LHS only after evaluating all
    value in the LHS register
                                         the RHS expressions in the design
Example
Intra-Assignment Delay
             always @(a or b) begin
A = #5 B;
             #5 y = a | b;      // value of a, b, 5 times steps later
C = D;
             end                // #5; y=a | b

             always @(a or b) begin
             y = #5 a | b;      // value of a, b, #0
             end                // y updated delayed, blocked


             always @(a or b) begin
             y <= #5 a | b;     // value of a, b, #0
             end                // y updated delayed, non-blocked
intra-assignment timing control, which delays the LHS
update, but not the RHS evaluation.
Verilog HDL Basics


  Flow Control, loop
Conditional Statement: if
    if ( expression ) statement_or_null [ else statement_or_null ]

    If (a<b) sum = sum +1;

    If (k==1)

    begin
    ........
    end
    If (a <b)

           sum = sum + 1;
    else
           sum = sum +2
    If (a>=b)

           begin
           .....               if (cond1) begin
           end                      if (cond2) do_c1_c2;
                                                            What is your
    else                            end                      LOGIC?
                               else
           begin
                               do_not_c1;
           .....
Example: if



              Priority
Conditional Statement: case




The Verilog case statement automatically breaks after the
first match
The case statement does a bit-by-bit comparison for an
exact match.
                                            Parallel
Conditional Statement: casez,
casex
Loop: for
Loop: forever, repeat
Loop: while
Summary
 What  we learned:
 Verilog basic Element, Data Type (net and reg)
 Event Driven Simulator Algorithm, IO supported
  system task
 Operator
 Continuous assignment, Procedure assignment
 Procedure timing control
 Flow control, loop
LAB2
Appendix

More Related Content

What's hot

Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDLanand hd
 
VHDL- gate level modelling
VHDL- gate level modellingVHDL- gate level modelling
VHDL- gate level modellingVandanaPagar1
 
Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog Pushpa Yakkala
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test BenchDr.YNM
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilogJITU MISTRY
 
Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Alok Singh
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation finalAnkur Gupta
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gatesRakesh kumar jha
 
gate level modeling
gate level modelinggate level modeling
gate level modelingVandanaBR2
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
Concepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLConcepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLanand hd
 

What's hot (20)

Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
 
VHDL- gate level modelling
VHDL- gate level modellingVHDL- gate level modelling
VHDL- gate level modelling
 
Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test Bench
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
 
Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gates
 
FPGA
FPGAFPGA
FPGA
 
PLDs
PLDsPLDs
PLDs
 
Verilog
VerilogVerilog
Verilog
 
gate level modeling
gate level modelinggate level modeling
gate level modeling
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Verilog HDL CODES
Verilog HDL CODES Verilog HDL CODES
Verilog HDL CODES
 
I2C BUS PROTOCOL
I2C BUS PROTOCOLI2C BUS PROTOCOL
I2C BUS PROTOCOL
 
Concepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLConcepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDL
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
 

Viewers also liked

Verilog HDL Training Course
Verilog HDL Training CourseVerilog HDL Training Course
Verilog HDL Training CoursePaul Laskowski
 
Easy Learn to Verilog HDL
Easy Learn to Verilog HDLEasy Learn to Verilog HDL
Easy Learn to Verilog HDLkpyes34
 
Verilog codes and testbench codes for basic digital electronic circuits.
Verilog codes and testbench codes for basic digital electronic circuits. Verilog codes and testbench codes for basic digital electronic circuits.
Verilog codes and testbench codes for basic digital electronic circuits. shobhan pujari
 
Day2 Open
Day2 OpenDay2 Open
Day2 OpenRon Liu
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesMalik Tauqir Hasan
 
Verilog Lecture4 2014
Verilog Lecture4 2014Verilog Lecture4 2014
Verilog Lecture4 2014Béo Tú
 
Functions and tasks in verilog
Functions and tasks in verilogFunctions and tasks in verilog
Functions and tasks in verilogNallapati Anindra
 
Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Béo Tú
 
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsJay Baxi
 
Engineer
EngineerEngineer
EngineerRon Liu
 
Digital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language VerilogDigital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language VerilogAbhiraj Bohra
 

Viewers also liked (20)

Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
Verilog HDL Training Course
Verilog HDL Training CourseVerilog HDL Training Course
Verilog HDL Training Course
 
Easy Learn to Verilog HDL
Easy Learn to Verilog HDLEasy Learn to Verilog HDL
Easy Learn to Verilog HDL
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Verilog codes and testbench codes for basic digital electronic circuits.
Verilog codes and testbench codes for basic digital electronic circuits. Verilog codes and testbench codes for basic digital electronic circuits.
Verilog codes and testbench codes for basic digital electronic circuits.
 
Day2 Open
Day2 OpenDay2 Open
Day2 Open
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
 
Verilog Lecture4 2014
Verilog Lecture4 2014Verilog Lecture4 2014
Verilog Lecture4 2014
 
Functions and tasks in verilog
Functions and tasks in verilogFunctions and tasks in verilog
Functions and tasks in verilog
 
Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014
 
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and Functions
 
Algorithms 1
Algorithms 1Algorithms 1
Algorithms 1
 
Engineer
EngineerEngineer
Engineer
 
test generation
test generationtest generation
test generation
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
Verilog
VerilogVerilog
Verilog
 
Digital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language VerilogDigital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language Verilog
 
verilog code
verilog codeverilog code
verilog code
 
Matlab isim link
Matlab isim linkMatlab isim link
Matlab isim link
 
Synthesis
SynthesisSynthesis
Synthesis
 

Similar to Verilog HDL Basics Guide

vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1MANDHASAIGOUD1
 
SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2alhadi81
 
CombVerilog.pdf
CombVerilog.pdfCombVerilog.pdf
CombVerilog.pdfashwkr07
 
Verilog_Overview.pdf
Verilog_Overview.pdfVerilog_Overview.pdf
Verilog_Overview.pdfQuangHuyDo3
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1manhduc1811
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLE2MATRIX
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptxSyedAzim6
 
dokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdfdokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdfVelmathi Saravanan
 
Advanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDLAdvanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDLTony Lisko
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfsagar414433
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfsagar414433
 
lecture8_Cuong.ppt
lecture8_Cuong.pptlecture8_Cuong.ppt
lecture8_Cuong.pptHongV34104
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhtsBéo Tú
 
Session 6 sv_randomization
Session 6 sv_randomizationSession 6 sv_randomization
Session 6 sv_randomizationNirav Desai
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Béo Tú
 

Similar to Verilog HDL Basics Guide (20)

vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
 
Verilogforlab
VerilogforlabVerilogforlab
Verilogforlab
 
SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2SKEL 4273 CAD with HDL Topic 2
SKEL 4273 CAD with HDL Topic 2
 
CombVerilog.pdf
CombVerilog.pdfCombVerilog.pdf
CombVerilog.pdf
 
verilog_tutorial1.pptx
verilog_tutorial1.pptxverilog_tutorial1.pptx
verilog_tutorial1.pptx
 
Verilog_Overview.pdf
Verilog_Overview.pdfVerilog_Overview.pdf
Verilog_Overview.pdf
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDL
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
 
dokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdfdokumen.tips_verilog-basic-ppt.pdf
dokumen.tips_verilog-basic-ppt.pdf
 
Advanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDLAdvanced Digital Design With The Verilog HDL
Advanced Digital Design With The Verilog HDL
 
Verilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdfVerilog Cheat sheet-2 (1).pdf
Verilog Cheat sheet-2 (1).pdf
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdf
 
Verilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdfVerilog_Cheat_sheet_1672542963.pdf
Verilog_Cheat_sheet_1672542963.pdf
 
lecture8_Cuong.ppt
lecture8_Cuong.pptlecture8_Cuong.ppt
lecture8_Cuong.ppt
 
verilog ppt .pdf
verilog ppt .pdfverilog ppt .pdf
verilog ppt .pdf
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
Session 6 sv_randomization
Session 6 sv_randomizationSession 6 sv_randomization
Session 6 sv_randomization
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
 

More from Ron Liu

Start up nations
Start up nationsStart up nations
Start up nationsRon Liu
 
XXX-Company-my viewpoints-2011-03-07
XXX-Company-my viewpoints-2011-03-07XXX-Company-my viewpoints-2011-03-07
XXX-Company-my viewpoints-2011-03-07Ron Liu
 
book digest: product design and development
book digest: product design and developmentbook digest: product design and development
book digest: product design and developmentRon Liu
 
The Hero Within
The Hero WithinThe Hero Within
The Hero WithinRon Liu
 
About Thinking
About ThinkingAbout Thinking
About ThinkingRon Liu
 
書摘Teach Your Child How To Think
書摘Teach Your Child How To Think書摘Teach Your Child How To Think
書摘Teach Your Child How To ThinkRon Liu
 
Day3 順序控制的組合邏輯實現
Day3 順序控制的組合邏輯實現Day3 順序控制的組合邏輯實現
Day3 順序控制的組合邏輯實現Ron Liu
 
Day4 Lab
Day4 LabDay4 Lab
Day4 LabRon Liu
 
Day4 Open
Day4 OpenDay4 Open
Day4 OpenRon Liu
 
Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Ron Liu
 
Day3 Lab
Day3 LabDay3 Lab
Day3 LabRon Liu
 
Day3 Quartus II Tutorial
Day3 Quartus II TutorialDay3 Quartus II Tutorial
Day3 Quartus II TutorialRon Liu
 
Day3 實驗板介紹
Day3 實驗板介紹Day3 實驗板介紹
Day3 實驗板介紹Ron Liu
 
Day2.Combinational Logic
Day2.Combinational LogicDay2.Combinational Logic
Day2.Combinational LogicRon Liu
 
Day2 Intro. Model Sim
Day2 Intro. Model SimDay2 Intro. Model Sim
Day2 Intro. Model SimRon Liu
 
Day2 Logic Circuits
Day2 Logic CircuitsDay2 Logic Circuits
Day2 Logic CircuitsRon Liu
 
Day1 Lab1
Day1 Lab1Day1 Lab1
Day1 Lab1Ron Liu
 
Day1 02.Introduction
Day1 02.IntroductionDay1 02.Introduction
Day1 02.IntroductionRon Liu
 
Day1 CourseIntroduction
Day1 CourseIntroductionDay1 CourseIntroduction
Day1 CourseIntroductionRon Liu
 
Free Lunch Talk Ron Nov 08
Free Lunch Talk Ron Nov 08Free Lunch Talk Ron Nov 08
Free Lunch Talk Ron Nov 08Ron Liu
 

More from Ron Liu (20)

Start up nations
Start up nationsStart up nations
Start up nations
 
XXX-Company-my viewpoints-2011-03-07
XXX-Company-my viewpoints-2011-03-07XXX-Company-my viewpoints-2011-03-07
XXX-Company-my viewpoints-2011-03-07
 
book digest: product design and development
book digest: product design and developmentbook digest: product design and development
book digest: product design and development
 
The Hero Within
The Hero WithinThe Hero Within
The Hero Within
 
About Thinking
About ThinkingAbout Thinking
About Thinking
 
書摘Teach Your Child How To Think
書摘Teach Your Child How To Think書摘Teach Your Child How To Think
書摘Teach Your Child How To Think
 
Day3 順序控制的組合邏輯實現
Day3 順序控制的組合邏輯實現Day3 順序控制的組合邏輯實現
Day3 順序控制的組合邏輯實現
 
Day4 Lab
Day4 LabDay4 Lab
Day4 Lab
 
Day4 Open
Day4 OpenDay4 Open
Day4 Open
 
Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現
 
Day3 Lab
Day3 LabDay3 Lab
Day3 Lab
 
Day3 Quartus II Tutorial
Day3 Quartus II TutorialDay3 Quartus II Tutorial
Day3 Quartus II Tutorial
 
Day3 實驗板介紹
Day3 實驗板介紹Day3 實驗板介紹
Day3 實驗板介紹
 
Day2.Combinational Logic
Day2.Combinational LogicDay2.Combinational Logic
Day2.Combinational Logic
 
Day2 Intro. Model Sim
Day2 Intro. Model SimDay2 Intro. Model Sim
Day2 Intro. Model Sim
 
Day2 Logic Circuits
Day2 Logic CircuitsDay2 Logic Circuits
Day2 Logic Circuits
 
Day1 Lab1
Day1 Lab1Day1 Lab1
Day1 Lab1
 
Day1 02.Introduction
Day1 02.IntroductionDay1 02.Introduction
Day1 02.Introduction
 
Day1 CourseIntroduction
Day1 CourseIntroductionDay1 CourseIntroduction
Day1 CourseIntroduction
 
Free Lunch Talk Ron Nov 08
Free Lunch Talk Ron Nov 08Free Lunch Talk Ron Nov 08
Free Lunch Talk Ron Nov 08
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Verilog HDL Basics Guide

  • 2. What we already learned  Verilog can model: behavioral, RTL structure  Module: basic unit in Verilog  A tutorial: Module instantiation, stimulus, respone  Procedure block: initial, always
  • 3. Verilog HDL Basics Basic Element and Data Type
  • 4. 4 Vaules Logic System
  • 6. Moudle Port Mapping  In Order − counter dut (count, clk, reset);  By Name − counter dut (.count(count), .clk(clk), .reset(reset));
  • 7. Comment and White Space module MUX2_1 (out, sel, inb, ina); // Port declarations, single line comments space, tab, and newline output out; input sel, inb, ina; // terminated with ; CASE Sensitive /* multiple lines comments The netlist logic selects input quot;inaquot; when sel is 0 and it selects ”inb” when sel is 1. */ not (sel_, sel); and (sela, ina, sel_), (selb, inb, sel ); or (out, sela, selb); endmodule
  • 8. Identifiers and Keywords Identifier: Names of instances, modules, nets, ports, and variables Keyword: Language construct, lower case module MUX2_1 (out,sel,inb,ina); output out; // names you provide such as input sel,inb,ina; // ina, inb, sel, sel_, sela, selb, out, not (sel_, sel); // and MUX2_1 are identifiers. and (sela, ina, sel_), (selb, inb, sel );
  • 9. Module ports // input [msb:lsb] list_of_port_identifier
  • 10. Data Type Devices/Blocks Storage Module parameters -Configure module instances
  • 11. Net  Nets are continuously driven by the devices that drive them. Ex, module or gate instantiation  Continuous assignments, primitives, and registers can drive nets.  Initial default value “z”
  • 12. Types of Net Examples // bit select wire [7:0] out ; assign out[1] =0 tri enable; // part-select wire a, b, c;
  • 13. Logic Conflicts Always be cautious about 『 multiple driver 』 on a net.
  • 14. Register A register maintains its value between discrete assignments.  assignments to registers in procedural code blocks, task or function.  Can't be output of “assign” statement.  Doesn't imply a storage element in the hardware.  Initial default value “x”
  • 15. Type of Register Examples: reg a; // single bit reg [3:0] b; // 4 bits reg [7:0] c, d; // two 8bits regs
  • 16. Parameters  Use module parameters to configure module instances: parameter list_of_assignments − A parameter is an un-typed constant − You can use a parameter anywhere that you can use a constant or liter
  • 18. Number [[<size>]’<radix>]<value>  − size is the size in bits − B or B (binary), o or O (octal), d or D (decimal), h or H (hexadecimal)  Examples 12 unsized decimal (extended to 32 bits with quot;0quot;) 'H83a unsized hexadecimal (extended to 32 bits with quot;0quot;) 8'b1100_0001 8-bit binary, _ for readability 8'h61 8-bit hex 64'hff01 64-bit hexadecimal (extended to 64 bits with quot;0quot;) 16'h456a 16-bit hex 9'O17 9-bit octal 32'bz01x extended to 32 bits with quot;zquot; 3’b1010_1101 3-bit number, truncated to 3’b101 6.3 decimal notation 32e-4 scientific notation for 0.0032 4.1E3 scientific notation for 4100
  • 19. String  string constants, but has no explicit string data type.  Store ASCII character strings in a reg array  Example: − $monitor(quot;This string formats a value: %bquot;, monitored_object); integer kkk; kkk = $fopen(file);
  • 20. Compiler Directives `define Define a text replacement macro `ifdef Conditionally compile source code, `else dependent upon which text macros `endif are defined `include Include a file of source code `resetall Reset all compiler directives `timescale Establish a simulation timescale `undef Undefine a text replacement macro
  • 21. timescale `timescale 1ns/100ps //time_unit, time_precision  Place the directive outside of a module definition seconds (s), milliseconds (ms), microseconds (us), nanoseconds (ns),  picoseconds (ps), or femtoseconds (fs)  to advance 1 ns simulation time `timescale 1 ns / 100 ps 10 steps `timescale 1 ns / 1 ps 1000 steps Delays are multiples of time_unit rounded to time_precision. `timescale 10ns/1ns #1.55 a = b; 'a' gets 'b' after 16 ns because 10ns*1.55 = 15.5 ns = 16ns rounded to nearest 1ns
  • 22. Memory: array of registers reg [MSB:LSB] memory_name [first_addr:last_addr];  reg [31:0] video_ram [0:7] // 8 words by 32 bit wide memory parameter wordsize = 16; parameter memsize = 1024; reg [wordsize-1:0] mem [0:memsize-1]; // arrays of integer and time data types: integer int_array [0:1]; // array of 2 integer variables time time_array [8:1]; // array of 8 time variables // the 3rd video_ram[2] = 1; $display(“video_ram[2] = %h”, video_ram[2]); // bit select not allowed for reg array
  • 24. Scope and Reference dut Module test_bench; Module ALU aa $monitor($time,quot;wire in A =%bquot;, dut.aa.a_in); Module A wire a_in bb Module B
  • 25. LAB
  • 26. Verilog HDL Basics Simulator, IO
  • 27. Event-Driven Simulation  The simulation scheduler − keeps track of when events occur, communicates events to appropriate parts of the model, − executes the model of those parts, and − as a result, possibly schedules more events for a future time. − Event-based simulation algorithms process only the changes in circuit state. − it maintains “simulated time” (sometimes “virtual time”) and the event list. − The simulation propagates values forward, through the circuit, in response to input pin events or autonomous event generators (such as clocks).
  • 28. Event-Driven Simulation  The simulator creates the initial queues upon compiling the data structures  The simulator processes all events on the current queue, then advances  The simulator moves forward through time, never backward  A simulation time queue represents concurrent hardware events
  • 29. System Tasks and Functions  names start with a dollar sign ($) character  Commonly used: Simulation Control, Display, File  Example $display $display(quot;out=%bquot;,out); // Display argument values $finish $finish; // Terminate the simulation $monitor $monitor($time,sel,a,b,out); // Monitor signal changes $stop $stop; // Suspend the simulation $time time_var = $time; // Get the simulation time Check doc see ModelSim support  <install_dir>docspdfoem_man.pdf chap5 But... what is %b....... 
  • 30. IO Format Specifier escape $monitor ($time, quot;%b t %h t %d t %oquot;, sig1, sig2, sig3, sig4); $display(quot;Hello World, count = %d quot;, count ); // new line added $write(quot;Hello World, count = %d nquot;, count ); // need escape
  • 31. Verilog HDL Basics Operator
  • 33. Operator: Arithmetic Example Integer division discards any remainder  A modulus operation retains the sign of the first operand  The integer register data type is signed.  The reg and time register data types are unsigned  reg [3:0] A, B; wire [4:0] sum, diff1, diff2, neg assign sum = A+B; assign diff1 = A-B; assign diff2 = B-A; assign neg = -A; $display(“%d %d %d %d %d %d”, A, B, sum, diff1, diff2, neg); $display(“%b %b %b %b %b %b”, A, B, sum, diff1, diff2, neg); ------------------------------------------------------------- A B A+B A-B B-A -A Stored in 2's complement 5 2 7 3 29 27 but .....unsigned. 0101 0010 00111 00011 11101 11011 If result is same size carry lost
  • 34. Operator: Bit Wise module bitwise_xor (y, a, b); input [7:0] a,b; output [7:0] y; assign y= a ^ b; //(0101_0101)^(0011_0000) = 0110_0101
  • 36. Operator: Logic reg [3:0] A, B 1. if (!A) // false if all of its bits are 0 if (A) // true if any of its bits are 1
  • 39. Operators: Shift result = (start << 1); // right operand treated as unsigned // so always use positive number
  • 40. Operator: Conditional if (conditional_expression) LHS = true_expression; else LHS = false_expression;quot; module mux41(O,S,A,B,C,D); module driver(O,I,E); output O; output O; input I,E; input A,B,C,D; input [1:0] S; assign O = E ? I : 'bz; assign O = (S == 2'h0) ? A : endmodule (S == 2'h1) ? B : (S == 2'h2) ? C : D; endmodule
  • 43. Operator Precedence Highest Lowest
  • 44. Verilog HDL Basics Assignment, timing control
  • 47. Example Use continuous assignments outside of a procedural block  Delay wire #5 eq = (a == b); Conditional
  • 48. forece..release  Apply to net as well as reg  Primarily used in testbench  force sig_a = 1;  release sig_a = 0;
  • 52. Example#1 To reg
  • 53. Example #2 When to start this block Cout = ( a & b) | ( a & !b &cin) | ( ); Sequential
  • 54. Procedural Timing Control: #  #0 IN1=0;IN2=1; // t=0  #100 IN3=1; // t=100  #100 IN4=1 // t=200
  • 55. Procedural Timing Control: @ Sensitivity List happened when signal transition Clock qualifier posedge, negedge ?? non-blocking assignment, later in this section
  • 56. Procedural Timing Control: wait // suspend here // until (ack || rst) true
  • 57. Missing Timing Control A zero-delay behavioral loop is a common coding error. In a zero-delay loop, the simulator continuously adds events to the same queue. As the queue never empties, the simulator appears to hang
  • 60. Example Initial Initial begin begin A=1; A=1; B=0; B=0; .... .... A=B; // Uses B=0 A<=B; // Uses B=0 B=A; // Uses A=0 B<=A; // Uses A=1 end end // A=0 // A=0 // B=0 // B=1 The simulator completes a The simulator completes a nonblocking   assignment (<=) in two passes: It blocking assignment (=) in one evaluates the RHS expression and pass: It evaluates the RHS schedules the LHS assignment. It expression and stores the updates the LHS only after evaluating all value in the LHS register the RHS expressions in the design
  • 62. Intra-Assignment Delay always @(a or b) begin A = #5 B; #5 y = a | b; // value of a, b, 5 times steps later C = D; end // #5; y=a | b always @(a or b) begin y = #5 a | b; // value of a, b, #0 end // y updated delayed, blocked always @(a or b) begin y <= #5 a | b; // value of a, b, #0 end // y updated delayed, non-blocked intra-assignment timing control, which delays the LHS update, but not the RHS evaluation.
  • 63. Verilog HDL Basics Flow Control, loop
  • 64. Conditional Statement: if if ( expression ) statement_or_null [ else statement_or_null ]  If (a<b) sum = sum +1;  If (k==1)  begin ........ end If (a <b)  sum = sum + 1; else sum = sum +2 If (a>=b)  begin ..... if (cond1) begin end if (cond2) do_c1_c2; What is your else end LOGIC? else begin do_not_c1; .....
  • 65. Example: if Priority
  • 66. Conditional Statement: case The Verilog case statement automatically breaks after the first match The case statement does a bit-by-bit comparison for an exact match. Parallel
  • 71. Summary  What we learned:  Verilog basic Element, Data Type (net and reg)  Event Driven Simulator Algorithm, IO supported system task  Operator  Continuous assignment, Procedure assignment  Procedure timing control  Flow control, loop
  • 72. LAB2