library ieee
use ieee.std_logic_1164.all
use ieee.std_logic_unsigned.all
use ieee.std_logic_arith.all
entity bit1adder is
port(
a,b,ci:in std_logic
s,co:out std_logic
)
end bit1adder
architecture func of bit1adder is
signal:x,y:std_logic
begin
x<=a xor b
y<=x and ci
s<=x xor ci
co<=y or (a and b)
end func
因为从begin到end func之间的语句是并行执行的,也就是说,这些语句同时执行,故仿真肯定错误。比如,你的第二段仿真波形,此时判察a=0,b=0,ci=0,那么x= 1,y=x and ci,注意,此时的x不是1而是0,故y=0,s=x xor ci,x=0,故s=0,co=0。可能是作者习惯了编写C,但在VHDL中一定要注意,语句一般是并行执行,除非是在PROCESS中。
因弯郑此可以做如下掘闹茄改正
s<= ci xor a xor b
co<= (a and b) or (ci and a) or (ci and b)
即消去中间变量,使得结果只和输入有关。
假设a和b是两个瞎世本位 *** 作数,c_in是低位向本位的进位,sum是本位和,c_out是本位向高位的进位磨基肢,都是std_logic类型的;input是进程体内声明的std_logic_vector类型的变量。只列出行为描述部分的代码,你需要用进程语句将其包装成并行语句:input := c_in &b &a
case input is
when "000" =>sum <= '0'c_out <= '0'
when "001"|"010"|"100" =>sum <= '1'c_out <= '0'
when "011"|"110"|"101" =>sum <= '0'c_out <= '1'
when "111" =>sum <= '1'c_out <= '1'
when others =>sum <= '-'c_out <= '-'锋桥
end case
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)