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 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.

Solutions

Expert Solution

VHDL CODE:::::

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.NUMERIC_STD.all;
entity ALU is
Port (A, B : in STD_LOGIC_VECTOR (31 downto 0);
ALUCntl : in STD_LOGIC_VECTOR (3 downto 0);
Carryin : in STD_LOGIC;
ALUOut : out STD_LOGIC_VECTOR (31 downto 0);
Zero : out STD_LOGIC;
Carryout : out std_logic;
Overflow : out STD_LOGIC);
end ALU;
architecture Behavioral of ALU is
signal ALU_Result : std_logic_vector (31 downto 0);
signal add_result,sub_result,a32,b32: std_logic_vector(32 downto 0);
signal c32: std_logic_vector(32 downto 0):=(others=>'0');
signal add_ov,sub_ov:std_logic;
begin
with ALUCntl select
ALU_Result <=add_result(31 downto 0) when "0010", --Add
sub_result(31 downto 0) when "0110", --sub
A AND B when "0000",
A OR B when "0001",
A XOR B when "0011",
A NOR B when "1100",
A when others;---condition for all other alu control signals
ALUOut <= ALU_Result;
----Addition Operation and carry out generation-----
a32 <='0'& A;
b32 <='0'& B;
c32 <=x"00000000" & Carryin;
add_result<=a32 + b32 + c32;
sub_result<=a32 - b32;
---Zero flag-----------------------------
Zero <= '1' when ALU_Result =x"00000000" else '0';
---Overflow flag---------------------------------------
add_ov<= (A(31)and B(31) and (not alu_result(31))) or ((not A(31))and (not B(31)) and alu_result(31));
sub_ov<= (A(31)and (not B(31)) and (not alu_result(31))) or ((not A(31))and B(31) and alu_result(31));
with ALUCntl select
Overflow<= add_ov when "0000",
sub_ov when "0001",
'Z' when others;
---Carryout-------------------------------------------------
With ALUCntl select
Carryout<= add_result(32) when "0010",
sub_result(32) when "0110",
'Z' when others;
end Behavioral;


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 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 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.
Write a VHDL code for a 8x8 bit multiplier. use structural approach. write the design code...
Write a VHDL code for a 8x8 bit multiplier. use structural approach. write the design code and testbench. Use for-generate if possible
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...
Write a program named problem.c to generate addition and subtraction math problems for a 4th grader....
Write a program named problem.c to generate addition and subtraction math problems for a 4th grader. 1. Your program will first ask user how many problems they want to do. 2. Repeat the following until you give user the number of problems that the user asks for.   a. Display the question number b. Generate a addition or subtraction problem using two random generated two digits (0-99). - The odd number of problems (1,3,5,…) will be addition problems. - The even...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT