有关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个整数, ...
随机推荐
- 汽车Vin码识别—— 一款二手车行业值得拥有的OCR识别软件
一.汽车Vin码识别产品描述 汽车Vin码识别系统,主要应用在智能手机IOS与Android两个平台中.前端扫描查询模式,无需联网,只需扫描汽车前挡风玻璃右下角的Vin码(车架号),即可轻松识别出车辆 ...
- Java文件流应用:剪切文件
剪切的实际操作是: 第一步,先复制文件到指定位置, 第二步,删除原文件,这样就实现了剪切 与复制文件相比,多了一步删除文件 注意:删除文件必须在流关闭后,才能删除,否则,删除不了. 实例代码 pack ...
- 用java来实现验证码功能。
昨天在网上看到了一篇关于验证码的文章,很不错,但是有些不尽人意的地方,比如没有考虑到前端传过来的验证码如果是小写的话,那么做验证的时候就会出现错误, 因为java是严格区分大小写的,还有就是验证码会重 ...
- Thinkphp 3.0-3.1版代码执行漏洞
近日360库带计划中播报的ThinkPHP扩展类库的漏洞已经查明原因:系官方扩展模式中的Lite精简模式中存在可能的漏洞(原先核心更新安全的时候 并没有更新模式扩展部分,现已更新).对于使用标准模式或 ...
- spring quartz开发中使用demo
1.首先在pom.xml中配置quartz的jar: <!--定时器--> <dependency> <groupId>org.quartz-scheduler&l ...
- 进程控制fork与vfork
1. 进程标识符 在前面进程描述一章节里已经介绍过进程的两个基本标识符pid和ppid,现在将详细介绍进程的其他标识符. 每个进程都有非负的整形表示唯一的进程ID.一个进程终止后,其进程ID就可以再次 ...
- logging模块
要想使用好logging模块首先要知道它的使用流程: logging类的实例化:logger=logging.getLogger('') 设置logger的级别,logger.setLevel(log ...
- DW3 消息推送
1.新建项目 参见:http://www.cnblogs.com/yysbolg/p/yys_Blogs_java.html 2.添加jar包: commons-fileupload-1.2.jar ...
- python cookbook第三版学习笔记 一
数据结构 假设有M个元素的列表,需要从中分解出N个对象,N<M,这会导致分解的值过多的异常.如下: record=['zhf','zhf@163.com','775-555-1212','847 ...
- MongoDB-配置翻译
Configuration File(配置文件) File Format(文件格式) Use the Configuration File(使用配置文件) Core Options(核心设置) sys ...