Mobile
Verilog Online Help Prev Page Prev Page
Table of Contents
Bit-select
Block Statements
Built-in Primitives
Case Statement
Continuous Assignments
Conversion Functions
Comments
Compiler Directives
Concatenations
Conditional Operator
Delays
Disable Statement
Display Tasks
Edge Sensitive Path
Expression Bit Length
File I/O Functions
Functions
Identifiers
If Statement
Integer Constants
Intra-assignment Timing Controls
Keywords
Loop Statements
Memories
min:typ:max Delays
Module Declaration
Module Instantiation
Module Path Declaration
Module Path Polarity
Net Data Types
Operators
Parameters
Part-select
PLA Modeling Tasks
Probabilistic Distribution Functions
Procedural Assignments
Procedural Continuous Assignments
Procedural Timing Control
Range Specification
Real Constants
Register Data Types
Simulation Control Tasks
Simulation Time Functions
Specify Block
State Dependent Path
Stochastic Analysis Tasks
Strengths
Strings
Structured Procedures
Tasks
Timescale System Tasks
Timing Check Tasks
UDP Declaration
UDP Instantiation
UDP State Table
Value Change Dump (VCD) File
Vectors

Expression Bit Length

Formal Definition

This chapter explains values for evaluation of size of expressions.

Description

Every expression has a result with a specified bit length. Therefore operand lengths should be checked before the expression is calculated to prevent the loss of important bits. This problem occurs when the result of an expression is assigned to a variable that cannot store all the result bits.


Expression

Bit length

Unsized constant number

Same as integer

Sized constant number

As given

i op j,

op: + - / % & | ^ ^~ ~^

Max(length of i, length of j)

i * j

Length of i + length of j

op i,

op: + - ~

Length of i

i op j,

op: == != === !== && || > >= < <=

1 bit

op i,

op: & ~& | ~| ^ ~^ ^~

1 bit

i op j,

op: >> <<

Length of i

i ? j : k

Max(length of j, length of k)

{i,j}

Length of i + length of j

{i{j,k}}

i * (length of j + length of k)

Table 2 Expression bit length rules

Examples

Example 1

reg [3:0] a;
reg [7:0] b;
reg [15:0] c;
a + b -> 8 bits
a * b -> 12 bits
a || b -> 1 bit
a >> 2 -> 4 bits
(c) ? a : b -> 8 bits
{i,j} -> 12 bits
{2(a,b}} -> 24 bits

Important Notes

  • The expression result bit-length should be known before the assignment to prevent unintended data loss.

 

Powered by IXwebhosting