Lecture 2: Continuation of SystemVerilog

Slides:



Advertisements
Similar presentations
VERILOG: Synthesis - Combinational Logic Combination logic function can be expressed as: logic_output(t) = f(logic_inputs(t)) Rules Avoid technology dependent.
Advertisements

Verilog.
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Combinational Logic.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
Combinational Logic with Verilog Materials taken from: Digital Design and Computer Architecture by David and Sarah Harris & The Essentials of Computer.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Verilog - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
ELEN 468 Lecture 151 ELEN 468 Advanced Logic Design Lecture 15 Synthesis of Language Construct I.
Discussed in class and on Fridays n FSMs (only synchronous, with asynchronous reset) –Moore –Mealy –Rabin-Scott n Generalized register: –With D FFs, –With.
Copyright © 2007 Elsevier4- Chapter 4 :: Hardware Description Languages Digital Design and Computer Architecture David Money Harris and Sarah L. Harris.
Computer Organization Lecture Set – 03 Introduction to Verilog Huei-Yung Lin.
Overview Logistics Last lecture Today HW5 due today
RTL Coding tips Lecture 7,8 Prepared by: Engr. Qazi Zia, Assistant Professor EED, COMSATS Attock.
each of these is an instantiation of “full_adder”
Combinational Logic in Verilog
Verilog Intro: Part 2. Procedural Blocks There are two types of procedural blocks in Verilog. – initial for single-pass behavior: initial blocks execute.
+ CS 325: CS Hardware and Software Organization and Architecture Combinational Circuits 1.
ECE 2372 Modern Digital System Design
1 Adders & Subtractors Adders –An adder is a combinational logic circuit that performs the addition of 2 binary numbers (A & B) to generate the sum (S)
1 COMP541 Verilog Primer Montek Singh Aug 28, 2015 (draft version  to be updated)
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Lecture 18: Hardware for Arithmetic Today’s topic –Intro to Boolean functions (Continued) –Designing an ALU 1.
ECE 331 – Digital System Design Single-bit Adder Circuits and Adder Circuits in VHDL (Lecture #11) The slides included herein were taken from the materials.
Discussed in class and on Fridays n FSMs (only synchronous, with asynchronous reset) –Moore –Mealy –Rabin-Scott n Generalized register: –With D FFs, –With.
1 COMP541 Hierarchical Design & Verilog Montek Singh Aug 29, 2014.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Verilog hdl – II.
Chapter 4 Computer System Architectures Chapter 4 Based on Digital Design and Computer Architecture, 2 nd Edition David Money Harris and Sarah L. Harris.
Chapter 6: Hierarchical Structural Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 6-1 Chapter 6: Hierarchical.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
ECE 111 (Spring 2017) Professor Bill Lin
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Chapter 4 Digital Design and Computer Architecture: ARM® Edition
Verilog Tutorial Fall
Montek Singh Sep 16, 2016 (draft version  to be updated)
COMP541 More on Verilog; Debouncing switches
Last Lecture Talked about combinational logic always statements. e.g.,
Hardware Description Languages
ELEN 468 Advanced Logic Design
Behavioral Style Combinational Design with VHDL
IAY 0600 Digital Systems Design
Lecture 3: Combinational Logic in SystemVerilog
Chapter 4 Digital Design and Computer Architecture, 2nd Edition
Supplement on Verilog adder examples
‘if-else’ & ‘case’ Statements
Chapter 4 Digital Design and Computer Architecture, 2nd Edition
Lecture 2 Supplement Verilog-01
Verilog-HDL-3 by Dr. Amin Danial Asham.
Behavioral Style Combinational Design with VHDL
Hardware Description Languages: Verilog
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
VHDL In this lecture, we will go over examples of VHDL in comparison to SystemVerilog Examples taken from Ch. 4 of the Harris & Harris book 2nd Edition.
Chapter 4 Combinational Logic
Behavioral Modeling in Verilog
COMP541 State Machines Montek Singh Feb 4, 2010.
More on Functions This lecture provides more ways of using functions
COE 202 Introduction to Verilog
Lecture 11: Hardware for Arithmetic
Supplement on Verilog adder examples
Supplement on Verilog combinational circuit examples
EEE2243 Digital System Design Chapter 1: Verilog HDL (Combinational) by Muhazam Mustapha, February 2012.
Introduction to Verilog – Part-2 Procedural Statements
COE 202 Introduction to Verilog
Combinational Circuit Design
Lecture 7: Verilog Part II
Presentation transcript:

Lecture 2: Continuation of SystemVerilog

Adder Examples module fulladder(input logic a, b, cin, output logic s, cout); logic p, g; // internal nodes assign p = a ^ b; assign g = a & b; assign s = p ^ cin; assign cout = g | (p & cin); endmodule Slide derived from slides by Harris & Harris from their book

Adder Examples /* hierarchical 4-bit adder */ module h4ba(input logic [3:0] A, B, input logic carry_in, output logic [3:0] sum, output logic carry_out); logic carry_out_0, carry_out_1, carry_out_2; // internal signals fulladder fa0 (A[0], B[0], carry_in, sum[0], carry_out_0); fulladder fa1 (A[1], B[1], carry_out_0, sum[1], carry_out_1); fulladder fa2 (A[2], B[2], carry_out_1, sum[2], carry_out_2); fulladder fa3 (A[3], B[3], carry_out_2, sum[3], carry_out); endmodule each of these is an instantiation of “full_adder”

Adder Examples module add4(input logic [3:0] A, B, output logic [3:0] sum); assign sum = A + B; endmodule Verilog compilers will replace arithmetic operators with default logic implementations (e.g. ripple carry adder) this expands into logic for a ripple carry adder

Numbers Format: N'Bvalue N = number of bits, B = base N'B is optional but recommended (default is decimal) Number # Bits Base Decimal Equivalent Stored 3'b101 3 binary 5 101 'b11 unsized 00…0011 8'b11 8 00000011 8'b1010_1011 171 10101011 3'd6 decimal 6 110 6'o42 octal 34 100010 8'hAB hexadecimal 42 00…0101010 Slide derived from slides by Harris & Harris from their book

Bit Manipulations: Example 1 assign y = {a[2:1], {3{b[0]}}, a[0], 6'b100_010}; // if y is a 12-bit signal, the above statement produces: // y = a[2] a[1] b[0] b[0] b[0] a[0] 1 0 0 0 1 0 // underscores (_) are used for formatting only to make // it easier to read. SystemVerilog ignores them. Slide derived from slides by Harris & Harris from their book

Bit Manipulations: Example 2 module mux2_8(input logic [7:0] d0, d1, input logic s, output logic [7:0] y); mux2 lsbmux(d0[3:0], d1[3:0], s, y[3:0]); mux2 msbmux(d0[7:4], d1[7:4], s, y[7:4]); endmodule Slide derived from slides by Harris & Harris from their book

More Examples module ex1(input logic [3:0] X, Y, Z, input logic a, cin, output logic [3:0] R1, R2, R3, Q1, Q2, output logic [7:0] P1, P2, output logic t, cout); assign R1 = X | (Y & ~Z); assign t = &X; assign R2 = (a == 1’b0) ? X : Y; assign P1 = 8’hff; assign P2 = {4{a}, X[3:2], Y[1:0]}; assign {cout, R3} = X + Y + cin; assign Q1 = X << 2; assign Q2 = {X[1], X[0], 1’b0, 1’b0}; endmodule use of bitwise Boolean operators example reduction operator conditional operator example constants replication, same as {a, a, a, a} example concatenation bit shift operator equivalent bit shift

Combinational logic using always module ex2(input logic a, b, c, output logic f); logic t; // internal signal always_comb begin t = a & b; f = t | c; end endmodule should use “=“ (called “blocking” assignment) in comb. logic always statements. RHS just takes output from the previous equation. The order of statements matters! takes output of “t” from previous equation

Combinational logic using always module ex3(input logic [3:0] d0, d1, input logic s, output logic [3:0] y); always_comb begin if (s) y = d1; else y = d0; end endmodule If-then-else translates into a 2:1 multiplexor Slide derived from slides by Harris & Harris from their book

Combinational logic using always /* behaviorial description of a 4-bit adder */ module p4ba(input logic [3:0] A, B, input logic carry_in, output logic [3:0] sum, output logic carry_out); logic [4:0] carry; // internal signal always_comb begin carry[0] = carry_in; for (int i = 0; i < 4; i++) begin sum[i] = A[i] ^ B[i] ^ carry[i]; carry[i+1] = A[i] & B[i] | A[i] & carry[i] | B[i] & carry[i]; end carry_out = carry[4]; endmodule entire “always_comb” block is called an “always statement” for combiantional logic for loops must have a specified range. simply interpreted as “replication”. Note we can declare the loop control variable within the for loop Verilog calls the use of “=“ inside an always statement as a “blocking” assignment. all it means is that the Verilog will “parse” the lines of code inside the always block in “sequential” order in the generation of logic. (will make more sense later when we discuss “non-blocking” assignments.)

Combinational logic using always

Combinational logic using case module sevenseg(input logic [3:0] data, output logic [6:0] segments); always_comb case (data) // abc_defg 0: segments = 7'b111_1110; 1: segments = 7'b011_0000; 2: segments = 7'b110_1101; 3: segments = 7'b111_1001; 4: segments = 7'b011_0011; 5: segments = 7'b101_1011; 6: segments = 7'b101_1111; 7: segments = 7'b111_0000; 8: segments = 7'b111_1111; 9: segments = 7'b111_0011; default: segments = 7'b000_0000; // required endcase endmodule case statement translates into a more complex “multiplexor” similar to if-then-else Slide derived from slides by Harris & Harris from their book

Combinational logic using case case statement implies combinational logic only if all possible input combinations described Remember to use default statement Otherwise, compiler will create an “asynchronous latch” to remember previous value: bad because this is not intended! Slide derived from slides by Harris & Harris from their book

Combinational logic using casez module priority_casez(input logic [3:0] a, output logic [3:0] y); always_comb casez(a) 4'b1???: y = 4'b1000; // ? = don’t care 4'b01??: y = 4'b0100; 4'b001?: y = 4'b0010; 4'b0001: y = 4'b0001; default: y = 4'b0000; endcase endmodule Slide derived from slides by Harris & Harris from their book

Nesting In general, for loop, if-then-else, and case statements can be “nested”. e.g., for (…) if (…) case (…) … endcase else … Compiler will compile from the “inner-most” scope outwards: i.e., it will first produce multiplexor logic for “case” statement, then produce multiplexor logic for the “if-then-else” part, then replicate all that logic based on the number of iterations in the “for loop”.

Functions /* adder subtractor */ module add_sub(input logic op, input logic [3:0] A, B, input logic carry_in, output logic [3:0] sum, output logic carry_out); function logic [4:0] adder(input logic [3:0] x, y, input logic cin); logic [3:0] s; // internal signals logic c; c = cin; for (int i = 0; i < 4; i++) begin s[i] = x[i] ^ y[i] ^ c; c = (x[i] & y[i]) | (c & x[i]) | (c & y[i]); end adder = {c, s}; endfunction always_comb if (op) // subtraction {carry_out, sum} = adder(A, ~B, 1); else {carry_out, sum} = adder(A, B, 0); endmodule function is like a comb. always statement, but can be called (instantiated) later.