有关conv_std_logic_vector和conv_integer
std_logic_arith
This is the library that defines some types and basic arithmetic operations for representing integers in standard ways. This is a Synopsys extention. The source code is instd_logic_arith.vhd and is freely redistributable.
The unsigned type
The signed type
The arithmetic functions: +, -, *
The comparison functions: <, <=, >, >=, =, /=
The shift functions: shl, shr
The conv_integer function
The conv_unsigned function
The conv_signed function
The conv_std_logic_vector function
-------------------------------------------------------------------------------------------------------------------------------
The conv_integer function
function conv_integer(arg: integer) return integer;
function conv_integer(arg: unsigned) return integer;
function conv_integer(arg: signed) return integer;
function conv_integer(arg: std_ulogic) return small_int;
These functions convert the arg argument to an integer. If the argument contains any undefined elements, a runtime warning is produced and 0 is returned.
The function provided by the std_logic_arith library can't convert a std_logic_vector to an integer because it is impossible to determine if it represents an unsigned or signed value.Functions that do this are included in the std_logic_unsigned and std_logic_signed libraries.
Examples
signal b : std_logic;
signal u1 : unsigned (3 downto 0);
signal s1 : signed (3 downto 0);
signal i1, i2, i3 : integer;
...
u1 <= "1001";
s1 <= "1001";
b <= 'X';
wait for 10 ns;
i1 <= conv_integer(u1); -- 9
i2 <= conv_integer(s1); -- -7
i3 <= conv_integer(b); -- warning produced in simulator
以上蓝字说明了一切
1.前一个包含在std_logic_arith.all程序包中
2.后一个在std_logic_unsigned 和std_logic_signed 中都有包含
计算机中的运算都是用2进制补码的,本人总结,在做算法时候,包含std_logic_signed 这个包比较好,这样conv_integer 就把需要转换的数据变成了带符号的整数,然而std_logic_unsigned就把需要转换的数据变成了无符号的整数。
3. conv_std_logic_vector 函数的转换结果是将被转换的数据先转换成2进制补码形式,然后取其低“位长”,作为输出。
如:a<=conv_std_logic_vector(-79,6)----(-79)2c=(10110001)
b<=conv_std_logic_vector(-2,6)-----(-2)2c=(11111110)
c<=conv_std_logic_vector(100,6)-----(100)2c=(01100100)
输出结果:a=110001,b=111110,c=100100
4.本人做了这样的转换conv_std_logic_vector (conv_integer (data),16),data是16范围内的有符号数,但是接口是32位的标准矢量形式(std_logic_vector(31 downto 0)刚开始包括的是std_logic_unsigned 包,发现数据变得面目全非了,想来想去,认为conv_integer (data)的原因,就该了下包,结果就正确了。
有关conv_std_logic_vector和conv_integer的更多相关文章
- VHDL学习之TEXTIO在仿真中的应用
TEXTIO 在VHDL 仿真与磁盘文件之间架起了桥梁,使用文本文件扩展VHDL 的仿真功能.本文介绍TEXTIO 程序包,以一个加法器实例说明TEXTIO 的使用方法,最后使用ModelSim 对设 ...
- VHDL数据类型转换
函 数 名 功 能 STD_LOGIC_1164包集合 TO_STDLOG ...
- VHDL 类型转换
STD_LOGIC_1164包集合 函 数 名 功 能 TO_STDLOGICVECTOR(A) 由BIT_VECTOR转换为STD_LOGIC_VECTOR TO_BITVECTOR(A) 由STD ...
- VHDL基础1
Description Structure 一个可综合的VHDL描述中一般由3部分组成:LIBRARY declarations.ENTITY.ARCHITECTURE Library(库)用来设计重 ...
- VHDL和verilog应该先学哪个?
网上有太多的VHDL和verilog比较的文章,基本上说的都是VHDL和verilog之间可以实现同一级别的描述,包括仿真级.寄存器传输级.电路级,所以可以认为两者是等同级别的语言.很多时候会了其中一 ...
- VHDL 数字时钟设计
序言 这个是我在做FPGA界的HelloWorld--数字钟设计时随手写下的,再现了数字钟设计的过程 目标分析 时钟具有时分秒的显示,需6个数码管.为了减小功耗采用扫描法显示 按键设置时间,需要对按键 ...
- 嵌入式CISC模型机设计
一. 课程设计的题目和内容 题目:设计一台嵌入式CISC模型计算机 采用定长CPU周期.联合控制方式,并运行能完成一定功能的机器语言源程序进行验证,机器语言源程序功能如下: 任意输入5个整数, ...
随机推荐
- elasticsearch 不能通过9200端口访问
修改配置文件 config/elasticsearch.yml network.host: 0.0.0.0
- 正则表达式入门案例C#
---恢复内容开始--- 在网上百度了好多关于正则表达式的,不过好多都是关于语法的,没有一个具体的案例,有点让人难以入门,毕竟我还是喜欢由具体到抽象的认识.所以我就在这先提供了一个入门小案例(学了了6 ...
- java将类和函数封装成jar,然后在别的项目中使用这个jar包
本来想用idea安装的,不过用maven生成后发现jar有20,30M肯定不对,后来还是用eclipse生成了,方便很多 环境: eclipse luna,jdk1.8_112 1.生成jar包,首先 ...
- sql还原(.mdf文件还原)
第一步: 把备份文件放到目录:C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA (默认)(这里用 MyDB.md ...
- Java阶段性测试--知识点:数组,面向对象,集合、线程,IO流
#Java基础测试 涉及知识点:数组,面向对象,重载,重写,继承,集合,排序,线程,文件流 一.多项选择题(可能是单选,也可能是多选) 1.下列标识符命名不合法的是( D ). A.$_Name ...
- Ch2. Loop Structure
Ex Input some integers and output their min, max and average values (keep three decimal places). It ...
- 通过wireshark学习Traceroute命令(UDP,ICMP协议)
traceroute: 通过TTL限定的ICMP/UDP/TCP侦测包来发现从本地主机到远端目标主机之间的第三层转发路径.用来调试网络连接性和路由问题. mtr: traceroute的一个变种,能根 ...
- 基于NopCommerce的开发框架——缓存、网站设置、系统日志、用户操作日志
最近忙于学车,抽时间将Nop的一些公用模块添加进来,反应的一些小问题也做了修复.另外有园友指出Nop内存消耗大,作为一个开源电商项目,性能方面不是该团队首要考虑的,开发容易,稳定,代码结构清晰简洁也是 ...
- Java经典编程题50道之三十六
有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数. public class Example36 { public static void main(String[] a ...
- CSS浮动、绝对、相对定位
浮动 float:属性{ float:none; 默认值,对象,不漂浮 float:left; 文本流向对象的右边 float:right; }; 清除浮动 clear:属性{ clear:no ...