ch10.04.htm
来自「介绍asci设计的一本书」· HTM 代码 · 共 103 行
HTM
103 行
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Mac">
<TITLE> 10.4 Identifiers and Literals </TITLE>
</HEAD><!--#include file="top.html"--><!--#include file="header.html"--><br><!--#include file="AmazonAsic.html"-->
<P><A NAME="pgfId=14404"></A><A HREF="CH10.htm">Chapter start</A> <A HREF="CH10.03.htm">Previous
page</A> <A HREF="CH10.05.htm">Next page</A></P>
<H2>10.4 Identifiers and Literals</H2>
<P><P CLASS="BodyAfterHead"><A NAME="pgfId=191355"></A>Names (the "nouns"
of VHDL) are known as identifiers [<A HREF="../../VHDL/LRM/HTML/1076_13.HTM#13.3">VHDL
LRM13.3</A>]. The correct "spelling" of an identifier is defined
in BNF as follows:</P>
<PRE>identifier ::=
letter {[underline] letter_or_digit}
<U>|\graphic_character{graphic_character}\</U></PRE>
<P><P CLASS="Body"><A NAME="pgfId=191359"></A>In this book an underline
in VHDL BNF marks items that are new or that have changed in VHDL-93 from
VHDL-87. The following are examples of identifiers:</P>
<PRE>s -- A simple name.
S -- A simple name, the same as s. VHDL is not case sensitive.
a_name -- Imbedded underscores are OK.
-- Successive underscores are illegal in names: Ill__egal
-- Names can't start with underscore: _Illegal
-- Names can't end with underscore: Illegal_
Too_Good -- Names must start with a letter.
-- Names can't start with a number: 2_Bad
\74LS00\ -- Extended identifier to break rules (VHDL-93 only).
VHDL \vhdl\ \VHDL\ -- Three different names (VHDL-93 only).
s_array(0) -- A static indexed name (known at analysis time).
s_array(i) -- A non-static indexed name, if i is a variable.</PRE>
<P><P CLASS="Body"><A NAME="pgfId=11809"></A>You may not use a reserved
word as a declared identifier, and it is wise not to use units, special
characters, and function names: <CODE>ns</CODE> , <CODE>ms</CODE> , <CODE>FF</CODE>
, <CODE>read</CODE> , <CODE>write,</CODE> and so on. You may attach qualifiers
to names as follows [<A HREF="../../VHDL/LRM/HTML/1076_6.HTM#6">VHDL LRM6</A>]:</P>
<PRE>CMOS.<B>all </B>-- A selected or expanded name, all units in library CMOS.
Data'LEFT(1) -- An attribute name, LEFT is the attribute designator.
Data(24 <B>downto </B>1) -- A slice name, part of an array: Data(31 downto 0)
Data(1) -- An indexed name, one element of an array.</PRE>
<P><P CLASS="Body"><A NAME="pgfId=14427"></A>Comments follow two hyphens
<CODE>'--'</CODE> and instruct the analyzer to ignore the rest of the line.
There are no multiline comments in VHDL. Tabs improve readability, but it
is best not to rely on a tab as a space in case the tabs are lost or deleted
in conversion. You should thus write code that is still legal if all tabs
are deleted.</P>
<P><P CLASS="Body"><A NAME="pgfId=282674"></A>There are various forms of
literals (fixed-value items) in VHDL [<A HREF="../../VHDL/LRM/HTML/1076_13.HTM#13.4">VHDL
LRM13.4</A>-<A HREF="../../VHDL/LRM/HTML/1076_13.HTM#13.7">13.7</A>]. The following
code shows some examples:</P>
<PRE><B>entity</B> Literals_1 <B>is</B> <B>end</B>;
<B>architecture</B> Behave <B>of</B> Literals_1 <B>is</B>
<B>begin process</B>
<B>variable</B> I1 : <B>integer</B>; <B>variable</B> Rl : <B>real</B>;
<B>variable</B> C1 : CHARACTER; <B>variable</B> S16 : STRING(1 <B>to</B> 16);
<B>variable</B> BV4: BIT_VECTOR(0 <B>to</B> 3);
<B> variable</B> BV12 : BIT_VECTOR(0 <B>to</B> 11);
<B>variable</B> BV16 : BIT_VECTOR(0 <B>to</B> 15);
<B>begin</B>
-- Abstract literals are decimal or based literals.
-- Decimal literals are integer or real literals.
-- Integer literal examples (each of these is the same):
I1 := 120000; Int := 12e4; Int := 120_000;
-- Based literal examples (each of these is the same):
I1 := 2#1111_1111#; I1 := 16#FFFF#;
-- Base must be an integer from 2 to 16:
I1 := 16:FFFF:; -- you may use a : if you don't have #
-- Real literal examples (each of these is the same):
Rl := 120000.0; Rl := 1.2e5; Rl := 12.0E4;
-- Character literal must be one of the 191 graphic characters.
-- 65 of the 256 ISO Latin-1 set are non-printing control characters
C1 := 'A'; C1 := 'a'; -- different from each other
-- String literal examples:
S16 := " string" & " literal"; -- concatenate long strings
S16 := """Hello,"" I said!"; -- doubled quotes
S16 := % string literal%; -- can use % instead of "
S16 := %Sale: 50%% off!!!%; -- doubled %
-- Bit-string literal examples:
BV4 := B"1100"; -- binary bit-string literal
BV12 := O"7777"; -- octal bit-string literal
BV16 := X"FFFF"; -- hex bit-string literal
<B>wait</B>; <B>end</B> <B>process</B>; -- the wait prevents an endless loop
<B>end</B>;</PRE>
<P><HR ALIGN="LEFT"></P>
<P><A HREF="CH10.htm">Chapter start</A> <A HREF="CH10.03.htm">Previous page</A> <A HREF="CH10.05.htm">Next page</A>
</BODY>
<!--#include file="Copyright.html"--><!--#include file="footer.html"-->
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?