Question

In: Electrical Engineering

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.

Solutions

Expert Solution

 library IEEE;

use IEEE.STD_LOGIC_1164.ALL ;

use IEEE.NUMERIC_STD.ALL ;

entity Simple_ALU is Port ( in_A, in_B : in STD_LOGIC_VECTOR(31 downto 0); --inputs of 32-bit Select : in STD_LOGIC_VECTOR(2 downto 0); -- to select the operation to be done ALU_Output : out STD_LOGIC_VECTOR(31 downto 0); -- Output of 32 bit ); end Simple_ALU;

- - The above code is for entity declaration and the input and output ports declaration.

- - For an ALU it is easy to use BEHAVIORAL model soo

architecture Behavioral of ALU is begin process(in_A,in_B,Select) -- based these inputs and select # operation is done begin case(Select) is when "000" => ALU_Output <= in_A + in_B ; -- # Addition of A and B when "001" => ALU_Output <= in_A - in_B ; -- # Subtraction of A and B when "010" => ALU_Output <= in_A and in_B; -- Logical and operation when "011" => ALU_Output <= in_A or in_B; -- Logical or operation when "100" => ALU_Output <= in_A xor in_B; -- Logical xor operation when "101" => ALU_Output <= in_A nor in_B; -- Logical nor operation when "110" => ALU_Output <= in_A nand in_B; -- Logical nand operation when "111" => -- Equal comparison if(A==B) then ALU_Output <= "1" ; -- Equal else -- Not Equal ALU_Output <= "0" ; end if; when others => ALU_Output <= in_A + in_B ; -- Here I prefer addition because end case; -- You ask ALU must perform Addition end process;
 end Behavioral;

It is a Simple VHDL code for a Simple ALU. In the ALU we have more operations like Multiplication, Division, Left Ship, Right Shift, Less Than, Greater Than, Rotational Shifts.


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 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.
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...
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....
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 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 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.
How do you write a VHDL code for this The SecondGenerator block generates the second count...
How do you write a VHDL code for this The SecondGenerator block generates the second count i.e; it increments an internal variable once every second from 0 to 59 and then rolls back to 0. That (std_logic_vector) variable can be assigned to a (std_logic_vector) signal second[5..0] which comes out of the block. Note that this is a 6-bit std_logic_vector value because counts up to 59 can be accommodated in 6 binary digits (26 = 64). As most clocks do not...
Using vhdl in a FSM , how could you write code to delay a state change...
Using vhdl in a FSM , how could you write code to delay a state change for one hour? For example, you have a fan running in the 'on' state , but after 1 hour you would like that fan to switch back to the 'off' state. What is the best way going about doing this?
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the...
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the following with 4 bit inputs , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT