二进制补码 VHDL

2023-12-04

我只是想用 VHDL 制作一个简单的二进制补码设备,但它抛出了这个非常烦人的错误,我不确定我做错了什么。可能是一些非常愚蠢的事情......错误是 “错误 (10327):twocompliment.vhd(21) 处的 VHDL 错误:无法确定运算符“nand”的定义 -- 找到 0 个可能的定义”

代码是

library ieee;
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all;
entity twoscompliment is
      generic
      (
              Nbits : positive := 8 
       );
 port 
( 
           --Inputs
           A : in std_logic_vector (Nbits-1 downto 0);
           --Outputs
           Y : out std_logic_vector (Nbits downto 0)
);
end twoscompliment;

architecture twoscompliment_v1 of twoscompliment is
 begin
  Y <= std_logic_vector(unsigned(A NAND '1') + '1');
 end twoscompliment_v1;

任何帮助都是极好的!


在我看来,你试图否定输入的数字......也许我错过了一些重要的东西,但其他答案给出了一种解决方案,该解决方案在实现目标的同时,似乎比他们需要的更加混乱。

除非丑陋的转换,有什么问题

y <= std_logic_vector(-signed(resize(unsigned(A)), y'length));

当然,我认为如果 A 和 Y 应该表示有符号数(或无符号数),那么它们应该表示为这样:

library ieee;
use ieee.numeric_std.all;
entity twoscomplement is
  generic
  (
     Nbits : positive := 8 
  );
  port 
  ( 
     A : in  unsigned (Nbits-1 downto 0);
     Y : out signed   (Nbits downto 0)
  );
end entity twoscomplement;

architecture a1 of twoscomplement is
begin
  Y <= -signed(resize(A, Y'length));
end architecture;

让我们检查一下结果:

entity test_twoscomplement is
end entity;

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
architecture test of test_twoscomplement is
    signal A : unsigned (7 downto 0);
    signal Y : signed(8 downto 0);
begin
    dut : entity work.twoscomplement port map (A => A, Y=>Y); 

    process
    begin
       for i in 0 to 255 loop
         A <= to_unsigned(i, A'length);
         wait for 1 ns;
         assert to_integer(Y) = -i severity error;
       end loop;
       report "tests done";
       wait;
     end process;
end architecture;

使用 GHDL 运行:

$ ghdl -a twoscomp.vhd 
$ ghdl --elab-run test_twoscomplement
twoscomp.vhd:40:8:@256ns:(report note): tests done

Success!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

二进制补码 VHDL 的相关文章

  • Xilinx ISE 14.7 设置编辑器字体大小

    左上角 edit preference
  • 来自不同进程的VHDL驱动信号

    我对以下 VHDL 代码有一个小问题 process zbroji begin if rising edge zbroji then oduzima lt 0 ucitanPrvi lt 1 broj1 lt ulaz broj end i
  • Altera Quartus 错误 (12007):顶层设计实体“alt_ex_1”未定义

    我看了之前所有的问题 似乎没有人有问题 和我的一样简单 我也在网上搜索过 但找不到解决方案 我是 VHDL 新手 正在尝试编译提供的简单示例 由Altera设计 如下 library ieee use ieee std logic 1164
  • VHDL:使用输入端口是不好的做法吗?

    我有一个程序 我按照以下方式使用 inout 端口 port inout unsigned 9 downto 0 if port gt 10 then port lt port 1 end if 我正在使用 inout 端口 这样我就可以读
  • 子状态机

    我有一个有 5 个州的 FSM 其中3个是通过子FSM UML模式 设计的 对于 VHDL 中的实现 恕我直言 有两种方法可以做到这一点 将它们总结为一个 这样我就有了一份包含子 FSM 的文档和一个包含一个大 FSM 的产品 与所有州建立
  • vhdl中的4位加法器

    我对 vhdl 语言还很陌生 所以请耐心等待 我刚刚为 1 位加法器编写了 vhdl 代码 但在为 4 位加法器编写时遇到了麻烦 这就是我到目前为止所得到的 如果有人能指出我要查找的内容的正确方向 那就太棒了 VHDL代码 LIBRARY
  • VHDL:对固定信号值进行零扩展

    如何对固定信号值进行零扩展 我有以下信号 signal shamt std logic vector 4 downto 0 在将其分配给另一个大小为 31 到 0 的变量之前 我必须将 shamt 归零 我有以下代码 但我不确定它是否正确
  • ERROR:Xst:827 = 信号计数无法合成,同步描述错误

    我正在尝试模拟电梯 结果出现错误 ERROR Xst 827 Signal count cannot be synthesized bad synchronous description 我正在关注此来源的代码 https www yout
  • VHDL——连接开关和LED

    我有 Xilinx Spartan6 和下一个 VHDL 代码 library ieee use ieee std logic 1164 all use ieee numeric std all entity Switches Leds i
  • VHDL乘法器

    library IEEE use IEEE STD LOGIC 1164 ALL entity Lab3 Adder1 is Port cin in STD LOGIC a in STD LOGIC VECTOR 3 downto 0 b
  • “等待上升沿(clk)”与“如果上升沿(clk)”有什么区别?

    我在 VHDL 中遇到了两种风格的过程语句 process clk begin if rising edge clk do something 另一种是 process begin wait until rising edge clk do
  • VHDL-读取HEX文件

    In VHDL 从 HEX 文件初始化 std logic vector 数组 https stackoverflow com questions 20164216 vhdl init std logic vector array from
  • 是否可以使用循环创建同一组件的多个实例?

    我有一个组件 Component CAU is port CLK in std logic RESET in std logic START in std logic V DIRECTION in vector 3d P ORIGIN in
  • 如何在 VHDL 中将整数作为十六进制写入标准输出?

    我可以打印一个integer作为十进制到标准输出 library std use std textio all entity min is end min architecture behav of min is begin process
  • VHDL 中的 BRAM_INIT

    我正在模拟基于处理器的设计 其中程序存储器内容保存在 BRAM 中 我正在使用 VHDL 推断 BRAM 实现程序存储器 我试图避免使用 CoreGen 因为我想保持设计的可移植性 最终该设计将进入 FPGA 我想看看是否有一种方法可以使用
  • VHDL - 分配默认值

    我有以下架构 architecture datapath of DE2 TOP is begin U1 entity work lab1 port map error on this line clock gt clock 50 key g
  • 仅使用 std_logic_vector 包将 std_logic_vector 与常量进行比较

    我仅在 VHDL 文件中使用以下包 library IEEE use IEEE STD LOGIC 1164 ALL 在代码中 我将 std logic vector 信号 A 与常量值进行比较 例如 if A lt 00001011 th
  • 在单周期数据路径中加载半字和加载字节

    有人询问如何在单周期数据路径中实现加载字节而无需更改数据存储器 解决方案如下 替代文本 http img214 imageshack us img214 7107 99897101 jpg http img214 imageshack us
  • VHDL 中的 #define 等价物是什么

    VHDL 中的 define ifdef 和 ifndef 相当于什么 我想使用泛型作为 define 并根据它们更改设计 举一个简单的例子 定义一个字符串泛型并用它来确定时钟是单时钟还是差分时钟 generic something boo
  • VHDL - ror 和 rol 操作

    我怎么解决这个问题 reg 变量定义为 signal reg STD LOGIC VECTOR 7 downto 0 00000001 下面代码中ror操作有问题 错误信息是 Line 109 Syntax error near ror L

随机推荐