나는 간단한 가산기를 구현 중이다. 그러나, 나는 약간의 독특한 트위스트의 필요성이있다.별도의 캐리 플래그와 빌로우 플래그로 간단한 애 더를 설계하는 방법은 무엇입니까?
구현중인 것은 코드 세그먼트 (CS) 레지스터와 명령어 포인터 (IP) 레지스터에서 "롤오버"기능입니다. 따라서 상대 점프를 +20으로하고 IP가 254이면 IP는 18로 끝나고 CS는 1 씩 증가합니다.
이 부분은 쉽고, 어려운 부분은 반대입니다 방향. 점프가 -20이고 IP가 0,은 1로 CS를 감소하고 지금까지 내 코드는 236
에 IP 롤 언더을 할 필요가있다 말할 때,의 차용을 감지
entity carryover is
port(
DataIn: in std_logic_vector(7 downto 0);
SegmentIn: in std_logic_vector(7 downto 0);
Addend: in std_logic_vector(7 downto 0); --How much to increase DataIn by (as a signed number). Believe it or not, that's the actual word for what we need.
DataOut: out std_logic_vector(7 downto 0);
SegmentOut: out std_logic_vector(7 downto 0);
);
end carryover;
architecture Behavioral of carryover is
signal temp: std_logic_vector(8 downto 0);
begin
--treat as unsigned because it doesn't actually matter for addition and just make carry and borrow correct
temp <= std_logic_vector(unsigned("0" & DataIn) + (unsigned)Addend);
DataOut <= temp(7 downto 0);
SegmentOut <= unsigned(SegmentIn) + 1 when (not temp(8)) and (not Addend(7)
end Behavioral;
하지만 차용을 감지하는 방법을 알아낼 수는 없습니다. 이 작업을 수행 할 수있는 명확한 방법이 있습니까?
업데이트
나의 새로운 코드는 이것이다 : 서명 숫자의
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.tinycpu.all;
entity carryover is
port(
EnableCarry: in std_logic; --When disabled, SegmentIn goes to SegmentOut
DataIn: in std_logic_vector(7 downto 0);
SegmentIn: in std_logic_vector(7 downto 0);
Addend: in std_logic_vector(7 downto 0); --How much to increase DataIn by (as a signed number). Believe it or not, that's the actual word for what we need.
DataOut: out std_logic_vector(7 downto 0);
SegmentOut: out std_logic_vector(7 downto 0)
-- Debug: out std_logic_vector(8 downto 0)
);
end carryover;
architecture Behavioral of carryover is
signal temp: std_logic_vector(8 downto 0);
begin
--treat as unsigned because it doesn't actually matter for addition and just make carry and borrow correct
process(DataIn, SegmentIn,Addend, EnableCarry)
begin
temp <= std_logic_vector(signed('0' & DataIn) + signed(Addend(7) & Addend));
if (EnableCarry and ((not Addend(7)) and (DataIn(7)) and temp(8)))='1' then
SegmentOut <= std_logic_vector(unsigned(SegmentIn)+1);
elsif (EnableCarry and (Addend(7) and (not DataIn(7)) and temp(8)))='1' then
SegmentOut <= std_logic_vector(unsigned(SegmentIn)-1);
else
SegmentOut <= SegmentIn;
end if;
end process;
--Debug <= Temp;
DataOut <= temp(7 downto 0);
end Behavioral;
추가 계획대로 작동하고, 온도는 이제 항상 올바른 결과이며, 아직 SegmentOut 항상 SegmentIn과 같다. 나는 왜 SegmentIn + 1
에 대해 실제로 Addend = 0x04, DataIn = 0xFE, SegmentIn = 0x00 및 CarryEnable = 1의 입력을 직접 계산했기 때문에 이해할 수 없다. if 문은 (1 and ((not 0) and 1 and 1))='1'
과 동일하지만 아직 SegmentOut은 변하지 않는다. 누구나 이것이 구현되는 방식에 문제가있는 것을 볼 수 있습니까? 피가수가 비트 비트 노래 합과 동일하지만 동일하지 않을 로그인 할 때
"깨끗한"이라고 말하면 비트 단위 확인을 의미합니까? 또한 부정적인 점프를 계획하는 경우 부호가있는 산술로 전환하여 해석자가 더하기 및 빼기가 발생할 수 있음을 이해하도록 할 수 있습니다. if 문을 사용하면 매우 간단 할 것이라고 생각하지만,이 문장이 "깨끗한"해결책이라고 생각하지는 않습니다. –