Slide 1 5. VHDL/Verilog Operators, Arrays and Indexes.

Slides:



Advertisements
Similar presentations
UNIT 8: Synthesis Basics
Advertisements

Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Chap. 6 Dataflow Modeling
Chapter 11 Verilog HDL Application-Specific Integrated Circuits Michael John Sebastian Smith Addison Wesley, 1997.
Table 7.1 Verilog Operators.
Slide 1 7. Verilog: Combinational always statements. VHDL: Combinational Processes: To avoid (I.E. DO NOT What in your HDL code?) Cases that generate Synthesis.
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.
Bitwise Operators Pointers Functions Structs Interrupts (in C)
ELEN 468 Lecture 151 ELEN 468 Advanced Logic Design Lecture 15 Synthesis of Language Construct I.
CS 3850 Lecture 4 Data Type. Physical Data Types The primary data types are for modeling registers (reg) and wires (wire). The reg variables store the.
DATAPATHS 3) Shifters. 4) Comparators 5) Counters.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Signals vs. Variables Workshop Fri/Sat Test bench creation Misc IP Cores Chipscope Pro When Demos due.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
Computer Organization Lecture Set – 03 Introduction to Verilog Huei-Yung Lin.
University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Digital System Design EEE344 Lecture 3 Introduction to Verilog HDL Prepared by: Engr. Qazi Zia, Assistant Professor EED, COMSATS Attock1.
each of these is an instantiation of “full_adder”
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
LOGIKAI TERVEZÉS HARDVERLEÍRÓ NYELVEN
1 Part V: VHDL CODING. 2 Design StructureData TypesOperators and AttributesConcurrent DesignSequential DesignSignals and VariablesState Machines A VHDL.
Dataflow Verilog ECEn 224.
Programmable Logic Architecture Verilog HDL FPGA Design Jason Tseng Week 5.
ECE 2372 Modern Digital System Design
Workshop Topics - Outline
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
C Operators. CONTENTS CONDITIONAL OPERATOR SIMPLE ASSIGNMENT OPERATOR COMPOUND ASSIGNMENT OPERATOR BITWISE OPERATOR OPERATOR PRECEDENCE.
Slide 1 2. Verilog Elements. Slide 2 Why (V)HDL? (VHDL, Verilog etc.), Karen Parnell, Nick Mehta, “Programmable Logic Design Quick Start Handbook”, Xilinx.
Verilog Language Concepts
IAY 0600 Digital Systems Design
RTL Hardware Design by P. Chu Chapter Basic VHDL program 2. Lexical elements and program format 3. Objects 4. Data type and operators RTL Hardware.
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Slide 1 2. Verilog Elements. Slide 2 Why (V)HDL? (VHDL, Verilog etc.), Karen Parnell, Nick Mehta, “Programmable Logic Design Quick Start Handbook”, Xilinx.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
3/4/20031 ECE 551: Digital System Design * & Synthesis Lecture Set 3 3.1: Verilog - User-Defined Primitives (UDPs) (In separate file) 3.2: Verilog – Operators,
Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.
CSE 351 Number Representation & Operators Section 2 October 8, 2015.
 Seattle Pacific University EE Logic System DesignMux-Decoder-1 Multiplexers Two alternative forms for a 2:1 Mux Truth Table Functional form Logical.
ECOM 4311—Digital System Design with VHDL
BASIC VHDL LANGUAGE ELEMENTS Digital Design for Instrumentation with VHDL 1.
ECOM 4311—Digital System Design with VHDL
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Slide 1 3.VHDL/Verilog Description Elements. Slide 2 To create a digital component, we start with…? The component’s interface signals Defined in MODULE.
Chapter 3: Dataflow Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 3-1 Chapter 3: Dataflow Modeling.
Case Study: Xilinx Synthesis Tool (XST). Arrays & Records 2.
Signed Arithmetic TYWu. Verilog 2001 Verilog 1995 provides only one signed data type, integer. Verilog 2001 provides a very rich set of new signed data.
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Hardware Description Languages: Verilog
IAY 0600 Digital Systems Design
CSE 220 – C Programming Expressions.
ELEN 468 Advanced Logic Design
Reg and Wire:.
TODAY’S OUTLINE Testbench Circuit Verilog Operators
Hardware Description Languages: Verilog
Chapter 3: Dataflow Modeling
332:437 Lecture 10 Verilog Language Details
CS 240 – Lecture 9 Bit Shift Operations, Assignment Expressions, Modulo Operator, Converting Numeric Types to Strings.
332:437 Lecture 10 Verilog Language Details
Advanced FPGA Based System Design
IAS 0600 Digital Systems Design
Computer Architecture
332:437 Lecture 10 Verilog Language Details
IAS 0600 Digital Systems Design
Number Representation & Operators
Reconfigurable Computing (EN2911X, Fall07)
Presentation transcript:

Slide 1 5. VHDL/Verilog Operators, Arrays and Indexes

Slide 2 Verilog for synthesis: What operators can we use? Operators can be used in both assign and always statements Logical bitwise operators: &, |, ~, ^, ~^ Operation applies to each bit of a signal Therefore, apply operators to signals with the SAME WIDTH only Otherwise, the signal with lower width will be left aligned (some synthesizers might align it to right) Logical operators: !, &&, ||, ==, !=, ===,, =, !== Used in conditions only. Same as in C, a condition is written always in () What is === and !== ? Signals are compared including X and Z Note: X = don’t care, not undefined! Applies to simulation only!

Slide 3 Verilog for synthesis: What operators can we use? Operators can be used in both assign and always statements Arithmetic operators: +, -, *, /, %, ** /, % and ** can be synthesized only if the second operand is 2 or power of 2! Shift: >, >> Shifted in values are 0 >> : shift and maintain sign bit Unary reduction operators &, ~&, |, ~|, ~, ^, ~^, Concatenate and replicate { }, {{}}

Slide 4 Verilog for synthesis: What operators can we use? Unary reduction operators Example: We have a N-bit wide signal named A. The width of A is determined by a parameter called SIGNAL_WIDTH. We have to make a logic AND between all of the bits of A into a signal called A_and. How can we do this? Solution 1: … wire [SIGNAL_WIDTH-1:0] A; reg A_and; integer I; (A) for (i=0; i<SIGNAL_WIDTH; i = i+1) A_and <= A_and & A[i]; Solution 2: … wire A_and; assign A_and = &A; Note: To test whether any of the bits of A is 1, one can use (|A)

Slide 5 Verilog for synthesis: What operators can we use? Concatenate and replicate Concatenate Examples: 1. {a, b, c} – Concatenate a, b, c into a bus The width of the resulting bus = width of a + width of b + width of c Concatenate assignment is also positional! The leftmost bit of the resulting bus is the leftmost bit of a 2. Assume the following code snippet: wire [7:0] a; wire [2:0] b; wire [4:0] c; wire [18:0] q; assign q = {a[5:0], c[3:0], b, a[7:6], 1’b0, 2’b10, b[2]}; What will be connected to q[17], q[7] and q[2]?

Slide 6 Verilog for synthesis: What operators can we use? Concatenate and replicate Replicate Examples: 1.We have a N-bit wide signal called A and a 1-bit wide signal called EN. The value of N is determined by the parameter SIGNAL_WIDTH. The EN signal acts as an enable for the N-bit wide output signal A_out such as A_out = A if EN = 1, otherwise all of the bits of A are 0. How can we do this? Solution 1: assign A_out = (EN)? A:0; //works only if A is less than 32-bit wide! Otherwise: N’h00…. Solution 2: assign A_out = A & {SIGNAL_WIDTH{EN}}; 2. wire [19:0] q = {{2{4’hA}}, {4{3’b101}}}. Write down in hexadecimal the value of Q!

Slide 7 Verilog for synthesis: About indexes One-dimension signals i.e. BUSES: How to access a part of a bus? Example: wire | reg [N:n] A; N and n are POSITIVE INTEGER numbers A[Upper:Lower] always represents the CONTINUOUS part of the bus having the width of Upper-Lower+1 Assume Upper >= Lower, then ALWAYS Upper =n! Otherwise the Verilog parser generates an error. Careful when using parameters or variables for indexing! The synthesizer is able to determine if the index is out of the range [N:n]. Example: reg [15:0] A; … for (i=0; i<=16; i++) A[i] <= … //will generate an error For selecting non-continuous parts of A, use concatenation operators A[i] ALWAYS represents a 1-bit wide signal. Obviously, n<=i<=N A ALWAYS represents the WHOLE range of A, equivalent to A[N:n] Note: A[N:N] is valid if A was defined in this way! Example: parameter SIGNAL_WIDTH = 0; reg [SIGNAL_WIDTH-1:0] A; //A will be defined as A[0:0]

Slide 8 Verilog for synthesis: About indexes One-dimension signals i.e. BUSES: How to access a part of a bus? Example: wire | reg [N:n] A; What about accessing part of A as A[Lower:Upper]? Syntactically it is accepted but the synthesizer will generate an error Use the endianness of signals in the way they wer defined! RECCOMENDATION: use only one endianness in your code! (usually little) If cannot avoid both little and big endian signals, in your code, Example: wire [Lower:Upper] B = A [Upper:Lower];//B[Lower] = A[Upper]… Two-dimension signals i.e. ARRAYS Example: reg [N:n] A [m:M]; //It can be also [M:m] Used mostly for MEMORY structures: RAM, ROM, FIFO and multi- dimensional shift registers ALWAYS THE SECOND INDEX COMES FIRST! A[ i ], m<= i <=M ALWAYS represents a N-n+1-width signal i.e the i-th location of the memory or shift register

Slide 9 Verilog for synthesis: About indexes Two-dimension signals i.e. ARRAYS Example: reg [N:n] A [m:M]; //It can be also [M:m] A[ i ], m<=i<=M ALWAYS represents a N-n+1-width signal i.e the i-th location of the memory or shift register, equivalent to A [ i ] [N:n] A[ i ][ j ], m<= i <=M, n <= i <= N ALWAYS represents bit j of location i A[ i ][Upper:Lower] ALWAYS represents a part selector of the bus from location i A [L1:U1] [U2:L2] is syntactically valid, but the synthesizer will generate an error For example: reg [7:0] Mem [0:255]; … begin Mem <= 0; //NOT ALLOWED. Mem is an array of 256X8! Not 32 bits //and not even 2048 bits! Mem [0:3] <= {32{1’b0}}; //Also not allowed Mem [3] <= 8’hFF;//Allowed Mem [255] [7:4] <= 4’h8;//Allowed

Slide 10 Verilog for synthesis: About indexes Multi-Dimension signals? Example: reg [N:n] A [m:M] [p:P]; //It can be also [m:M], [P:p] and so on It will be visible as a three-dimensional memory ALWAYS, THE SECOND INDEX COMES FIRST! XST solves the three-dimensional array as a two-dimensional array of (P-p+1) * (N-n+1) X (M-m+1) The third index i.e. [p:P] represents a multiplier for the first index i.e. [N:n] Therefore A[ i ] [ j ], m<= i <=M, p <= j <= P represents a N-n+1-width signal i.e the i-th location, bits [ (( j+1 ) * N) + j : (( j+1 ) * N ) + j – (N-n) ] of the memory, or shift register, equivalent to A [ i ] [ j ] [N:n] A[ i ][ j ][ k ], m<= i <=M, p <= i <= P, n <= k <=N represents bit j*k of location i A[ i ][ j ][Upper:Lower] represents a part selector [ (j * Upper: j * Lower] of the bus from location i A [L1:U1] [U2:L2] is not accepted by the synthesizer, it will generate an error Example: reg [7:0] Mem [0:255][0:3]; //will generate an array of 256 X 32- bit wide registers

Slide 11 VHDL: About indexes One-dimension signals i.e. BUSES: Example: signal A: std_logic_vector (7 downto 0); signal B, C: std_logic_vector (0 to 3); Index can be also negative! Part selectors: Valid: A (5 downto 4); B(0 to 2); A (5 downto 5); C(0 to 3); Invalid, even syntactically is not accepted to change the endianness or using indexes larger than the range: A (3 to 7); B(3 downto 0); C(0 downto 0); A(8), A(6 downto -1); A is equivalent to A(7 downto 0), B to B(0 to 3) and so on 1-bit value: enclosed in ‘ ‘, multiple-bit values: enclosed in “ “ Hexadecimal prefix: X Concatenation operator: &. Examples: A <= C & B; -- A(7) <= C(0), A(6) <= C(1) and so on A <= ‘0’ & B &”000”; A<= X”FF”; B <= C(0 to 2) & ‘1’;

Slide 12 VHDL: About indexes Multi-dimension signals i.e. ARRAYS: First, the type of array has to be defined. Example: type my_mem2type is array (0 to 7) of std_logic_vector ( 15 downto 0); type my_mem3type is array (0 to 3) of my_mem2type; signal A: my_mem2type; signal B: my_mem3type; The first defined index comes first! Part selectors: similar to Verilog A(7); A(5) (5 downto 4); B(3) (7) (15); Invalid: A (3 to 7); B(2 to 3) etc.