OSDN Git Service

adc test added.
[motonesfpga/motonesfpga.git] / simulation / cpu / alu / alu_adc.vhd
1
2 library ieee;
3 use ieee.std_logic_1164.all;
4 use ieee.std_logic_unsigned.all;
5
6
7 --* Add Memory to Accumulator with Carry: ADC
8 --* A + M + C -> A
9 --* Flags: N, V, Z, C
10
11 entity alu_adc is
12     port (  a, b    : in std_logic_vector (7 downto 0);
13             sum       : out std_logic_vector (7 downto 0);
14             cin         : in std_logic;
15             cout        : out std_logic;
16             n, v, z : out std_logic
17             );
18 end alu_adc;
19
20 architecture rtl of alu_adc is
21 signal adc_work : std_logic_vector (8 downto 0);
22 begin
23     adc_work <= ('0' & a) + ('0' & b) + ("0000000" & cin);
24
25     sum <= adc_work(7 downto 0);
26
27     cout <= adc_work(8);
28     v <= '1' when (a(7) = '0' and b(7) = '0' and adc_work(7) = '1') else
29          '1' when (a(7) = '1' and b(7) = '1' and adc_work(7) = '0') else
30          '0';
31
32     n <= '1' when (adc_work(7) = '1') else
33          '0';
34     z <= '1' when (adc_work(7 downto 0) = "00000000") else
35          '0';
36
37 end rtl;
38