Question

In: Electrical Engineering

Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication,...

Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication, shift right, shift left, logical NAND, and logical NOR. Write a VHDL test bench to test the ALU with at least one test vector per operation.

Solutions

Expert Solution

-----------------------------------------
-- OpCode Output (Y)
------------------------------------------
-- 000 A + B
-- 001 A - B
-- 010 B - A
-- 011 A * B
-- 100 A shift right by 1 bit
-- 101 A shift left by 1 bit
-- 110 A logical NAND with B
-- 111 A logical NOR with B
------------------------------------------

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

-- assume A and B are of 4 bits, and output Y are of 8 bits
-- sel is the selection bit between different operation

entity alu_design is
port (
  A : in std_logic_vector ( 3 downto 0 );
  B : in std_logic_vector ( 3 downto 0 );
  OpCode : in std_logic_vector ( 2 downto 0 );
  Y : out std_logic_vector ( 7 downto 0 )
);
end alu_design;

architecture behavioral of alu_design is
signal tempA, tempB : std_logic_vector(7 downto 0);
  begin
   -- To make it compile clean
   tempA <= '0' & '0' & '0' & '0' & A(3 downto 0);
   tempB <= '0' & '0' & '0' & '0' & B(3 downto 0);

   process(tempA, tempB, OpCode)
   begin
   case OpCode is
   when "000" => Y <= tempA + tempB;
   when "001" => Y <= tempA - tempB;
   when "010" => Y <= tempB - tempA;
   when "011" => Y <= tempA(3 downto 0) * tempB(3 downto 0);
   when "100" => Y <= '0' & tempA(7 downto 1);
   when "101" => Y <= tempA(6 downto 0) & '0';
   when "110" => Y <= tempA nand tempB;
   when "111" => Y <= tempA nor tempB;
   when others => Y <= A;
   end case;
   end process;

end behavioral;



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

entity alu_design_tb is
end alu_design_tb;

architecture testbench of alu_design_tb is
component alu_design
port (
  A : in std_logic_vector ( 3 downto 0 );
  B : in std_logic_vector ( 3 downto 0 );
  OpCode : in std_logic_vector ( 2 downto 0 );
  Y : out std_logic_vector ( 7 downto 0 )
);
end component;

signal A, B : std_logic_vector(7 downto 0);
signal OpCode : std_logic_vector(2 downto 0);
signal Y : std_logic_vector(7 downto 0);

begin


dut : alu_design port map (A => A, B => B, OpCode => OpCode, Y => Y);

process
  begin
   A <= "1100";
   B <= "0111";
   OpCode <= "000";
   wait for 10 ns;

   OpCode <= "001";
   wait for 10 ns;

   OpCode <= "010";
   wait for 10 ns;

   OpCode <= "011";
   wait for 10 ns;

   OpCode <= "100";
   wait for 10 ns;

   OpCode <= "101";
   wait for 10 ns;

   OpCode <= "110";
   wait for 10 ns;

   OpCode <= "111";
   wait for 10 ns;
   wait;

end process;

end testbench;


Related Solutions

Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed to use other libraries. Only this libraries are allowed to use: use library ieee; use ieee.std_logic_1164.all; Please do it correctly and include the comments for me to fully understand. Thank you.
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed to use other libraries only this is allowed to use library ieee; use ieee.std_logic_1164.all; Please write the comments for me to fully understand. Thank you.
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The program will add, subtract, multiply, or divide 2 numbers and provide the average of multiple numbers inputted from the user. You need to define a function named performCalculation which takes 1 parameter. The parameter will be the operation being performed (+,-,*,/). This function will perform the given prompt from the user for 2 numbers then perform the expected operation depending on the parameter that’s...
You are supposed to build a custom ALU that can perform the following operations: Multiplication Addition...
You are supposed to build a custom ALU that can perform the following operations: Multiplication Addition Division Logical OR Select all necessary components below, to create this ALU. Multiplexer Demultiplexer OR gate AND gate NOT gate Encoder Priority Encoder Decoder Adder Subtractor Multiplier Divider Shifter Register Register File
1) Perform the following addition and subtraction operations. For subtraction, negate the subtrahend (the second value)...
1) Perform the following addition and subtraction operations. For subtraction, negate the subtrahend (the second value) and add. For each operation, show the interpretation as both unsigned and signed operations. Indicate whether an unsigned or signed overflow has occurred that invalidates the result under that interpretation. Use an eight bit byte for all operations and for the signed interpretation, use two’s complement representation. Spaces are used in the binary values only for readability a. 1001 1111 + 0111 1000 b....
Problem: Perform following operations in binary using 8-bit addition/subtraction/multiplication. 1. −80 + 42 2. −99 −...
Problem: Perform following operations in binary using 8-bit addition/subtraction/multiplication. 1. −80 + 42 2. −99 − 20 3. 60 − 70 4. −59 × 3 5. 52×−1
What is the primary reason that addition and subtraction are considered more complex than multiplication and...
What is the primary reason that addition and subtraction are considered more complex than multiplication and division with floating-point representations? What are subnormal numbers, and how do subnormal numbers help reduce the impact of underflow?
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code of 4-bit modulo-9 counter in ModelSim, and capture the screenshot of your simulated waveform. Assume clock period Tclk=100ns, initially, the counter is reset to Q3Q2Q1Q0=0000 you need to simulate a complete counting cycle plus one more additional clock period after it is reset to “0000” state.
Write a C++ program to perform two-4 bit binary number operations including addition and subtraction. The...
Write a C++ program to perform two-4 bit binary number operations including addition and subtraction. The user will type in two-4 bit binary numbers with the selection of one of the operations. Then, the program will calculate the result of the calculation. Display two-4 bit binary numbers and the result from the calculation.
write sample code in VHDL Design and implementation of Pressetable ripple counter using behavioral style of...
write sample code in VHDL Design and implementation of Pressetable ripple counter using behavioral style of modeling by using pic74196
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT