Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write code simple calculator with vhdl and test bench Solution Library IEEE; Use

ID: 3687233 • Letter: W

Question

write code simple calculator with vhdl and test bench

Explanation / Answer

Library IEEE; Use IEEE.STD_CALC_PAK is Package MY_CALC_PAK is Type MY_RECORD is Record OP_CODE : std_logic_vector(3 downto 0); -- opcode A_IN : std_logic_vector(3 downto 0); --A operand B_IN : std_logic_vector(3 downto 0); --B operand C_IN : std_logic; -- C_In operand Exp out : std_logic_vector(3 downto 0); -- expected output End record; end MY_CALC_PAk; LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.ALL; use CALC1_PAK.ALL; ENTITY CNTRL_FSM_Tb-vhd IS END CNTRL_FSM_TB_vhd; ARCHITECTUTER behavior OF CNTRL_FSM_TB-vhd IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT CNTRL_FSM PORT( DATA_FRAME : IN MY_RECORD; CLK : IN std_logic; RESET: IN std_logic; MEM_EN : OUT std_logic; ADDR : OUT std_logic_vector(3 downto 0); ALU_EN : OUT std_logic; A_IN : OUT std_logic_vector(3 downto 0); B_IN : OUT std_logic_vector(3 downto 0); OP_CODE : OUT std_logic_vector(3 downto 0); C_IN : OUT std_logic; COMP_EN : OUT std_logic; EXP : OUT std_logic_vector(3 downto 0); ); END COMPONENT; -- Inputs SIGNAL DATA_FRAME : MY-RECORD := (A_IN=> *0111*, B_IN=>*0011*, OP_CODE =>*0000*, C_IN=> ‘0’, EXP_OUT=>”0111”); SIGNAL CLK : std_logic :=’0’; SIGNAL RESET: std_logic :='0'; -- Outputs SIGNAL MEM_EN : std_logic; SIGNAL ADDR : std_logic_vector(3 downto 0); SIGNAL ALU_EN : std_logic; SIGNAL A_IN : std_logic_vector(3 downto 0); SIGNAL B_IN : std_logic_vector(3 downto 0); SIGNAL OP_CODE : std_logic_vector(3 downto 0); SIGNAL C_IN : std_logic; SIGNAL COMP_EN : std_logic; SIGNAL EXP : std_logic_vector(3 downto 0); BEGIN -- Instantiate the Unit Under Test (UM) uut: CNTRL_FSM PORT MAP( DATA_FRAME => DATA_FRAME, CLK => CLK RESET => RESET. MEM_EN => MEM_EN. ADDR => ADDR. ALU_EN => ALU_EN, A IN => A_IN, B_IN => B_IN, OP_CODE => OP_CODE, C_IN => C_IN, COMP EN => COMP_EN, EXP=>EXP ); CLK ”l0l0"), --add 6 => (OP_CODE=>”001l”,A_IN=>”0111",B_IN=>”0011",c_in=>’0',EXP_0UT=>"l010”), --addc 7 => (OP_CODE=>"0011”,A_IN=>”0111”,B_IN=>”0011”,c_in=>’0’,EXP_0UT=>"1011”), --addc 8 => (OP_CODE=>"0100”,A_IN=>”0111",B_IN=>”0011”, c_in=>’0’,EXP_0UT=>"0100”), --sub 9 => (OP_CODE.=>”0100”,A_IN=>”0111",B_IN=>"0011”, c_in=>’0’,EXP_0UT=>"0100”), --sub 10 => (OP_CODE=>"0101”,A_IN=>”0111",B_IN=>”0011”, c_in=>’0’,EXP_0UT=>"1000”), --Comp 11 => (OP_CODE=>"0111",A_IN=>”0111”,B_IN=>”0011”, c_in=>’0’,EXP_0UT=>"1000”), --Comp 12 => (OP_CODE=>”0110”,A_IN=>”0111",B_IN=>”0011", c_in=>’0’,EXP_0UT=>"1001”), --neg 13 => (OP_CODE=>”0110”,A_IN=>”0111",B_IN=>”0011”, c_in=>’0’,EXP_0UT=>"1001”), --neg 14 => (OP_CODE=>”0111”,A_IN=>”0111",B_IN=>"0011", c_in=>’0’,EXP_0UT=>"0110”), --dec 15 => (OP_CODE=>”0111”,A_IN=>”0111",B_IN=>”0011”, c_in=>’0’,EXP_0UT=>"0110”), --dec 16 => (OP_CODE=>”1000”,A_IN=>”0111",B_IN=>"0011", c_in=>’0’,EXP_0UT=>"0011”), --txb 17 => (OP_CODE=>"1000”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0011”), --txb 18 => (OP_CODE=>"1001”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0011”), --and I9 => (OP_CODE=>"1001”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0011”), --and 20 => (OP_CODE=>"1010”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0111”), --or 21 => (OP_CODE=>"1010”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0111”), --or 22 =:> (OP_CODE=>"1011”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0100”), --xor 23 => (OP_CODE=>"1011”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0100”), --xor 24 => (OP_CODE=>"1100”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"1110”), --sl 25 => (OP_CODE=>"1100”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"1110”), --sl 26 => (OP_CODE=>"0011”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0011”), --sr 27 => (OP_CODE=>"1101”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0011”), --sr 28 => (OP_CODE=>"1110”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0001”), --Par 29 => (OP_CODE=>"1110”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UT=>"0000”), --Par 30 => (OP_CODE=>"1111”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UI'=>"0000”), --zero 31 => (OP_CODE=>"1111”,A_IN=>”0111”,B_IN=>”0011",c_in=>’0’,EXP_0UI'=>"0000”), --zero