名称:8位二进制硬件乘加器
软件:QuartusII
语言:VHDL
代码功能:
8位二进制硬件乘加器
要求:yout= a0 x b0+a1 x b1;
ao、bo、a1、b1均为8位二进制有符号数,能同时显示乘数、被乘数 积的信息(LED数码管)。
本代码已在DE0-CV开发板,KX-CDS-CV5实验箱验证成功,开发板及实验箱如下:
代码下载:
FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com
部分代码展示
LIBRARY ieee; USE ieee.std_logic_1164.all; --顶层模块 ENTITY mult IS PORT ( clk : IN STD_LOGIC;---时钟 rst_p : IN STD_LOGIC;--复位--实验箱键1 data_in : IN STD_LOGIC_VECTOR(7 DOWNTO 0);--二进制输入--核心板SW0~7,SW设置8位2进制有符号数,然后按key_a0就将该数输入到程序中,key_b0,key_a1,key_b1类似 key_a0 : IN STD_LOGIC;--a0按键--核心板key0 key_b0 : IN STD_LOGIC;--b0按键--核心板key1 key_a1 : IN STD_LOGIC;--a1按键--核心板key2 key_b1 : IN STD_LOGIC;--b1按键--核心板key3 key_enter : IN STD_LOGIC;--计算按键--实验箱键2 --实验箱数码管显示端口 a0_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); a0_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b0_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b0_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); a1_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); a1_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b1_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b1_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); --核心板数码管显示端口 HEX0 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX1 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX2 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX3 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0) ); END mult; ARCHITECTURE behave OF mult IS COMPONENT display IS PORT ( a0 : IN STD_LOGIC_VECTOR(7 DOWNTO 0); b0 : IN STD_LOGIC_VECTOR(7 DOWNTO 0); a1 : IN STD_LOGIC_VECTOR(7 DOWNTO 0); b1 : IN STD_LOGIC_VECTOR(7 DOWNTO 0); result : IN STD_LOGIC_VECTOR(15 DOWNTO 0); a0_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); a0_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b0_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b0_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); a1_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); a1_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b1_H : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); b1_L : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); HEX0 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX1 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX2 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0); HEX3 : OUT STD_LOGIC_VECTOR(6 DOWNTO 0) ); END COMPONENT; COMPONENT mult_ctrl IS PORT ( clk : IN STD_LOGIC; rst_p : IN STD_LOGIC; data_in : IN STD_LOGIC_VECTOR(7 DOWNTO 0); key_a0 : IN STD_LOGIC; key_b0 : IN STD_LOGIC; key_a1 : IN STD_LOGIC; key_b1 : IN STD_LOGIC; key_enter : IN STD_LOGIC; a0_o : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); b0_o : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); a1_o : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); b1_o : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); result_o : OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ); END COMPONENT; SIGNAL a0 : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL b0 : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL a1 : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL b1 : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL result : STD_LOGIC_VECTOR(15 DOWNTO 0); BEGIN --调用控制模块 i_mult_ctrl : mult_ctrl PORT MAP ( clk => clk, rst_p => rst_p, data_in => data_in, key_a0 => key_a0, key_b0 => key_b0, key_a1 => key_a1, key_b1 => key_b1, key_enter => key_enter, a0_o => a0, b0_o => b0, a1_o => a1, b1_o => b1, result_o => result ); --调用显示模块 i_display : display PORT MAP ( a0 => a0, b0 => b0, a1 => a1, b1 => b1, result => result, a0_H => a0_H, a0_L => a0_L, b0_H => b0_H, b0_L => b0_L, a1_H => a1_H, a1_L => a1_L, b1_H => b1_H, b1_L => b1_L, HEX0 => HEX0, HEX1 => HEX1, HEX2 => HEX2, HEX3 => HEX3 ); END behave;