0% found this document useful (0 votes)
9 views19 pages

Verilog 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views19 pages

Verilog 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

VERILOG -2

11-9-23
ECE/EEE/INSTR F215 (DIGITAL DESIGN)
PROF. ANITA AGRAWAL, BITS, PILANI- K.K.BIRLA GOA CAMPUS
INTEGER CONSTANTS

ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 2


INTEGER CONSTANTS

 Integer constants/numbers: decimal by default.


 Preceded by a minus sign for negative value. Default:
unsigned integer.
 Other number systems: hexadecimal, octal, binary should be
specified as such,

 'b or 'B : binary (0,1)


 'o or 'O : octal (0-7)
 'h or 'H : hex (0-9, A-F or a-f)
 'd or 'D : decimal (0-9)
10/6/2023 12:35 AM 3
ANITA AGRAWAL CS/ECE/EEE/INSTR F215
UNSIZED INTEGERS

 Integer default size (unsized): 32 bits (compiler defined)


 Sized value: must be preceeding the base declaration.
 Must be an unsigned decimal number
 Should specify the number of bits required to represent the
number.
 If the specified integer constant requires less bits than the
specified size, it is:
 left padded with zeros
 left padded with ’x’ or ‘z’ if leftmost is ‘x’ or ‘z’
ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 4
USE OF ‘-’ CHARACTER

 Can be used anywhere inside the number, except as the first


character.

 Only used to enhance readability, as spaces are not allowed inside


the numbers and are ignored by compiler.

ANITA AGRAWAL CS/ECE/EEE/INSTR F215


10/6/2023 12:35 AM 5
EXAMPLE

 16’b1001_1100_1110_0001

 197_832_001

ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 6


USE OF X & Z CHARACTERS

 The digits ‘x’ or ‘X’ and ‘z’ or ‘Z’ : unknown and high
impedance’ values, respectively.
 Can be used in binary, octal and hexadecimal numbers
(not in decimal)
 A single ‘x’ or ‘z’ extends to four bits if used in a
hexadecimal number, to three in octal, and one in
binary.
ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 7
EXAMPLES

 4’b01xx // last two bits of this four bit number unknown.

10/6/2023 12:35 AM 8

ANITA AGRAWAL CS/ECE/EEE/INSTR F215


USE OF ‘?’ CHARACTER

 Can be used as a digit instead of ‘z’ (high impedance) for readability


purposes, especially when the high impedance is a don’t care condition.
 Sets four bits to ‘z’ in hexadecimal numbers, three bits in octal and one
in binary.
 Cannot be used with decimal numbers.

ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 9


OPERATORS

ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 10


Operator Operator Operation Number
Type Symbol performed of
operands
Arithmetic * Multiply two
/ Divide two
+ Add two
- Subtract two
% Modulus two
** Power two
(exponent)
Arithmetic + Specifies one
(unary) sign of
operand
ANITA AGRAWAL CS/ECE/EEE/INSTR F215
- “ one 11

10/6/2023 12:35 AM
EXAMPLE
Let A=4’b0011, B=4’b0100, D=6, E=4, F=2

 A*B

 A+B

 B –A

 D/E

 D%E

 F = E ** F

 Note: If any operand bit has a value x, then the result of the entire expression is x. 12

10/6/2023 12:35 AM
ANITA AGRAWAL CS/ECE/EEE/INSTR F215
SOME MORE EXAMPLES……

Ex: W = 4’b101x, Y=4’b1011, then W+Y = 4’bx

 13 % 3 = 1 ; 13/3 = 4
 16 % 4 = 0 ; 16/4 = 4
 -7 % 2 = -1 ; -7/2 = -3
 7 % -2 = 1 ; 7/-2 = 3

ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 13


Operator Operator Operation Number
Type Symbol performed of
operands
Logical ! Logical one
negation
&& Logical two
and
|| Logical or two

Always evaluate to a 1-bit value, 0 (false) or 1 (true) or x(ambiguous if


any operand is x or z)
ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 14
A=4 B=0
A && B //evaluates to 0 ; logical 1 && logical 0
A || B //evaluates to 1; logical 1 || logical 0
!A // evaluates to 0
!B // evaluates to 1
Unknowns
A = 2’b0x; B =2’b10
A && B //evaluates to x ; equivalent to (x && logical 1)

Expressions
(a==2) && (b==3) //evaluates to 1 if both a ==2 and
b==3 are true, else to 0
10/6/2023 12:35 AM 15
ANITA AGRAWAL CS/ECE/EEE/INSTR F215
Operator Type Operator Operation Number of
Symbol performed operands
Relational > Greater than two
< Less than two
>= Greater than two
or equal

<= Less than or two


equal

Equality == Equality two


!= Inequality two
=== Case equality two

ANITA AGRAWAL CS/ECE/EEE/INSTR F215


!== Case inequality two 16

10/6/2023 12:35 AM
Relational operators:

Return values 1,0 or x when used in an expression

Akin to C language

ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 17


Equality operators:
•compares the two operators bit by bit
•Fills up with 0s in case of unequal lengths

Logical: ==, !=

Case: ===, !==

Logical operators, outputs: 1,0, x

Case operators, outputs: 1,0


ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:35 AM 18
ANITA AGRAWAL CS/ECE/EEE/INSTR F215 10/6/2023 12:40 AM 19

You might also like