VHDL学习笔记——数据类型转换

对象分类

  • 信号:通过信号赋值语句改变值;
signal 信号名:数值类型 := 初始值;
  • 常量:初始化后不能改变;
  • 变量:通过变量赋值语句改变值;
  • 文件:内部存储一组某种数据的对象;

对象类型

  • 标量类型:单一不可再分,数值/枚举型
  • 混合类型:数组型/记录型(数组内元素同一类型、记录内元素不同类型)
  • 访问类型:对象的访问方式(类似指针)
  • 文件类型:文件值为代表该文件的文件序号;
  • 被保护类型:多进程访问同一变量时,提供原子访问与排他访问。
IEEE库数据类型转换函数
程序包函数名功能
std_logic_1164to_stdlogicvector(A)bit_vector转换为std_logic_vector
std_logic_1164to_bitvector(A)std_logic_vector转换为bit_vector
std_logic_1164to_stdlogic(A)由bit转换为std_logic
std_logic_1164to_bit(A)std_logic类型转换为bit类型
std_logic_arithconv_std_logic_vector(A,位长)integer转换为std_logic_vector,A为整数
std_logic_arithconv_integerstd_logic_vector转换为integer
std_logic_arithconv_unsigned(A,位长)unsigned、signed、integer转换为指定位长的unsigned
std_logic_arithconv_signed(A,位长)unsigned、signed、integer转换为指定位长的signed
std_logic_unsignedconv_integer(A)std_logic_vector转换为integer
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity conv is
	port(
	a1,a2 : in bit_vector(3 downto 0);
	c1,c2,c3 : in std_logic_vector(3 downto 0);
	b1,b2,b3 : integer range 0 to 15;
	d1,d2,d3,d4 : out std_logic_vector(3 downto 0)
	);
end entity conv;

architecture beve of conv is
	begin
		d1 <= to_stdlogicvector(a1 and a2);
		d2 <= conv_std_logic_vector(b1,4) when conv_integer(b2)=9
			else conv_std_logic_vector(b3,4);
		d3 <= c1 when conv_integer(c2) = 8 else c3;
		d4 <= c1 when c2 = 8 else c3;
end architecture beve;


转换函数conv_integer();

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity conv is
	port(
	input: in std_logic_vector(2 downto 0);
	output: out std_logic_vector(7 downto 0)
	);
end entity conv;

architecture beve of conv is
	begin
		process(input) begin
		output <= (others => '0');
		output(conv_integer(input))<='1';
		end process;
end architecture beve;


  • 1
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值