超前进位加法器(32位)

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

entity adder32 is
    port(
        a, b: in std_logic_vector(31 downto 0);
        s: out std_logic_vector(31 downto 0)
    );
end entity adder32;   

architecture adder32_behiv of adder32 is
signal p : std_logic_vector(31 downto 0);
signal q : std_logic_vector(31 downto 0);
signal c : std_logic_vector(31 downto 0);
begin

        p <= a and b;
        q <= a or b;

。。。。。。。。。。。。(C代码生成的文件填入此处)

        s <= p xor q xor (c(30 downto 0) & "0");
       
end architecture adder32_behiv;

 

============================================

#include
#include

int main()
{
    FILE *fp = fopen("adder.vhd", "w");

    for (int i = 0; i < 32; ++i){
        fprintf(fp, "c(%d) <= p(%d) ", i, i);
        int j = i - 1;
        while (j >= 0){
            fprintf(fp, "or (p(%d) ", j);
            for (int k = 0; k < i - j; ++k){
                fprintf(fp, "and q(%d)", i-k);
            }
            fprintf(fp, ")");
            j--;
        }
        fprintf(fp, ";\n");
    }

    fclose(fp);
    return 0;
}

 

你可能感兴趣的:(FPGA)