Re: [vhdl-200x] Support for hex, octal, binary in places where integers can be used

From: Colin Paul Gloster <Colin_Paul_Gloster@ACM.org>
Date: Thu Dec 20 2012 - 04:06:38 PST
On December 20th, 2012, Martin Stolpe emailed:
|------------------------------------------------------------------------|
|"Hello,                                                                 |
|                                                                        |
|currently VHDL doesn't seem to support a construct which allows the     |
|usage of hex numbers instead of integer numbers. For example sometimes  |
|I encode my addresses like this:                                        |
|                                                                        |
|CONSTANT                                                                |
| C_ADDRESS_WIDTH                                                        |
|  : integer := 4;                                                       |
|                                                                        |
|CONSTANT                                                                |
| C_READ_DATA                                                            |
|  : unsigned(C_ADDRESS_WIDTH - 1 DOWNTO 0) :=                           |
| to_unsigned(1, C_ADDRESS_WIDTH);                                       |
|                                                                        |
|it would be nice if I could write it like this or something similar:    |
|                                                                        |
|CONSTANT                                                                |
| C_ADDRESS_WIDTH                                                        |
|  : integer := 12;                                                      |
|                                                                        |
|CONSTANT                                                                |
| C_READ_DATA                                                            |
|  : unsigned(C_ADDRESS_WIDTH - 1 DOWNTO 0) :=                           |
| to_unsigned(0x1, C_ADDRESS_WIDTH);                                     |
|                                                                        |
|This way if I have to adjust the address width there would be just one  |
|position in the code which I would have to modify. The hexadecimal      |
|coding would be more in line with the address encoding the              |
|microcontroller programmers use. Other suggestions would be welcomed    |
|though.                                                                 |
|                                                                        |
|                                                                        |
|Best regards                                                            |
|i.A. Martin Stolpe                                                      |
|                                                                        |
|                                                                        |
|----------------------------------------------------------------------- |
|                                                                        |
|Systemingenieur                                                         |
|R&D Smart Embedded Systems (SW)                                         |
|                                                                        |
|NewTec GmbH                                                             |
|System-Entwicklung und Beratung                                         |
|Heinrich-von-Stephan-Str. 8B                                            |
|D-79100 Freiburg                                                        |
|                                                                        |
|Telefon  : +49 (0) 761 21117-40                                         |
|Telefax  : +49 (0) 761 21117-41                                         |
|email    : martin.stolpe@newtec.de                                      |
|web      : http://www.newtec.de                                         |
|                                                                        |
|------------------------------------------------------------------------|
|Geschäftsführer: Johannes Werbach, Harald Molle, Ulrich Schwer,         |
|Michael Tröscher                                                        |
|Registergericht: Memmingen - HRB 7236 USt.-IdNr. DE130850199            |
|------------------------------------------------------------------------|
|                                                                        |
|                                                                        |
|                                                                        |
|-- This message has been scanned for viruses and dangerous content by   |
|   MailScanner, and is believed to be clean."                           |
|------------------------------------------------------------------------|

Dear Mr. Stolpe:

VHDL already supports hexadecimal; decimal; octal; binary; and other bases.

Subsubsubsection 15.5.3 Based literals
of IEEE Std 1076-2008
contains some examples:
-- Integer literals of value 255:
    2#1111_1111#                16#FF#                016#0FF#
-- Integer literals of value 224:
    16#E#E1                     2#1110_0000#
-- Real literals of value 4095.0:
    16#F.FF#E+2                 2#1.1111_1111_111#E11


Furthermore,
Subsubsection 15.8 Bit string literals
shows that "111111111111" is equivalent to B"1111_1111_1111". So if we have a 
fourteen-bit value and a fifteen-bit value, we could tell at a glance that they 
are of different lengths by looking at B"11_1111_1111_0000" and 
B"111_1111_1111_0000".

It may be worthwhile getting some tips from a book such as
"The Designer's Guide to VHDL",
WWW.Eason.Ie/look/9780120887859/Designer-s-Guide-to-VHDL/Peter-Ashenden
and
WWW.ElsevierDirect.com/product.jsp?isbn=9780120887859
and
WWW.Ashenden.com.Au/vhdl-book/DG3E.html
or if you can not get hold of that, then maybe
"Digital Design: An Embedded Systems Approach Using VHDL",
http://textbooks.Elsevier.com/web/product_details.aspx?isbn=9780123695284&Search=9780123695284&SearchCriteria=Keyword

Yours sincerely,
Paul Colin Gloster

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Dec 20 04:09:24 2012

This archive was generated by hypermail 2.1.8 : Thu Dec 20 2012 - 04:09:32 PST