EXPRESSIONS

Expressions in EasyHDL consist of terms separated by operators. A term consists of an optional unary operator followed by either a literal value, a variable or constant, a function, or the result of a sub-expression that is enclosed in parentheses.

Operators

The following operators are all valid in EasyHDL:

Operator Description

()

Parentheses

-

Unary minus

!

Unary logical NOT

~

Unary bitwise NOT

AND or &&

Logical AND

OR or ||

Logical OR

&

Bitwise AND

|

Bitwise OR

^

Bitwise XOR

<=

Less than or equal

<

Less than

= or ==

Equal

<>, != or ><

Not Equal

>

Greater than

>=

Greater than or equal

<<

Left Shift

>>

Right Shift

+

Addition

-

Subtraction

*

Multiplication

/

Division

%

Modulus

A sub-expression in parentheses is always evaluated first, and a unary operator always binds to the term that follows it. Beyond that, operator precedence is defined, in decreasing order, as

  1. Modulus, Division, Multiplication.
  2. Addition, Subtraction.
  3. Left and Right Shift.
  4. Bitwise AND.
  5. Bitwise XOR.
  6. Bitwise OR.
  7. Less than, Less than or equal, Greater than, Greater than or equal.
  8. Equals, Not equals.
  9. Logical AND and OR.

The three unary operators are - (arithmetic negation), ! (logical NOT) and ~ (bitwise NOT). The words AND and OR may be written in place of && and ||, but there is no corresponding word form for either NOT operator.

Values

Values can be either variables, system variables, system constants, the result of functions, the results of sub-expressions (evaluated by enclosing the expression in brackets), or literal numbers. Literal numbers can be specified in decimal, in hexadecimal (by preceding the number with a dollar character or with 0x) or in binary (by preceding the value with a percent character or with 0b). All values can be modified by preceding them with a unary operator.

Values Description

23

Decimal value, 23 decimal

%1010

Binary value 1010 (10 decimal)

$010A

Hexadecimal value 010A (266 decimal)

0b1010

Binary value 1010 (10 decimal)

0x010A

Hexadecimal value 010A (266 decimal)

10n

Decimal value with an engineering suffix, 10 nanoseconds

(10*5)

Sub-expression, 10*5 (50 decimal)

TRUE

System constant, TRUE

!TRUE

Unary operator and constant, NOT TRUE

max_count

Variable, max_count

EVTTIME

System variable, EVTTIME

~%1010

Unary Bitwise NOT (5 decimal)

!$A

Unary Logical NOT (0 decimal)

"Hello"

String constant

Engineering Suffixes

A numeric literal may be followed immediately by an engineering suffix, which multiplies it by the corresponding power of ten. This is the notation used for the times and component values in the examples throughout this chapter, so SLEEP FOR 20n sleeps for twenty nanoseconds and FLOAT PERIOD=10m sets the period to ten milliseconds.

Suffix Multiplier

p

pico, 10-12

n

nano, 10-9

u

micro, 10-6

m

milli, 10-3. This suffix is recognised in lower case only.

k or K

kilo, 103

M

mega, 106. This suffix is recognised in upper case only.

G

giga, 109

T

tera, 1012

The pico, nano and micro suffixes are also accepted in upper case. Case is significant for milli and mega, however, so take care to write 10m for ten milliseconds and 10M for ten million.

There is no femto suffix. The letters r, v, a, f and h are read as unit letters, for resistance, volts, amps, farads and henries, and leave the value unchanged, so 10f means ten and not ten femto.

Evaluation Precedence Examples

Here are some example expressions:

Expression Answer

2 * -3 + 4

Evaluates as -2

2 * -(3 + 4)

Evaluates as -14

5 << 3

Evaluates as 40

10 >> 2

Evaluates as 2

3 << 3+4

Evaluates as 28

20-3*4

Evaluates as 8

2<1+3

Evaluates as 1 (i.e. TRUE, 2<4)

1+2>=8

Evaluates as 0 (i.e. FALSE, 3>=8)

40%16

Evaluates as 8

!(1<3)

Evaluates as 0 (i.e. FALSE, !TRUE)

!5<2

Evaluates as 1 (i.e. TRUE, 0<2)

Functions

EasyHDL supports several useful mathematical and string functions. A function consists of the function name followed by its arguments, enclosed in parentheses and separated by commas; each argument may be an expression. Most functions take a single argument, but POW takes two and SUBSTR takes two or three. The result of the function is returned as its value. For example, the following expression assigns the square-root of the expression a*b*c to the variable z:

z = sqrt (a*b*c)

EasyHDL supports the following functions:

Function Description

DEG

Returns its argument in degrees which must be in radians.

RAD

Returns its argument in radians which must be in degrees.

SIN

Returns the sine of its argument which must be in radians.

COS

Returns the cosine of its argument which must be in radians.

TAN

Returns the tangent of its argument which must be in radians.

ASIN

Returns the arc-sine of its argument in radians.

ACOS

Returns the arc-cosine of its argument in radians.

ATAN

Returns the arc-tangent of its argument in radians

SQRT

Returns the square-root of its argument.

LN

Returns the natural logarithm of its argument.

EXP

Returns e raised to the power of its argument, the inverse of LN.

POW

Returns the first argument raised to the power of the second. This function takes two arguments.

ROUND

Returns the its argument as rounded to the nearest integer.

FRAC

Returns the decimal part of its floating-pointing argument.

ASC

Returns the ASCII code of the first character in a string

CHR

Returns a single character corresponding to the ASCII code of the argument.

LEN

Returns the length of a string

SUBSTR

Returns a substring of a string argument starting at the second argument and of the length given by the optional third argument. This function takes two or three arguments.

See Also:

Variables

System Constants and Variables

Command Reference