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.
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
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...
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in...
There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in 1st grade focus on addition. They are required to memorize their addition facts from 1 to 12. Create a function that prompts the user to enter a number between 1 and 12. Then display - using the input supplied - the addition and subtraction math facts for that number from 1 to 12 for the number entered. The output should be the results of...
There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in...
There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in 1st grade focus on addition. They are required to memorize their addition facts from 1 to 12. Create a function that prompts the user to enter a number between 1 and 12. Then display - using the input supplied - the addition and subtraction math facts for that number from 1 to 12 for the number entered. The output should be the results of...
Write a C++ arithmetic calculator program that performs four arithmetic operations namely addition, subtraction, multiplication and...
Write a C++ arithmetic calculator program that performs four arithmetic operations namely addition, subtraction, multiplication and division. This program prompts user to enter data in the following order: First data is the number, second data is an operator and the third data is the number. You are required to: Write a function for addition. Write a function for subtraction. Write a function for multiplication. Write a function for division. Write a main program which calls four functions based on the...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT