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

LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY Alu4 IS GENERIC(CONSTANT N: IN

ID: 644986 • Letter: L

Question

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

ENTITY Alu4 IS
GENERIC(CONSTANT N: INTEGER:=4;    --4 BITS ALU
          CONSTANT Z: STD_LOGIC_VECTOR(3 DOWNTO 1):="000" --3 ZEROs
          );
PORT(a,b: IN STD_LOGIC_VECTOR(N-1 DOWNTO 0);
       control: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
       overflow: OUT STD_LOGIC;
       zero: OUT STD_LOGIC;
       carryOut: OUT STD_LOGIC;
       result: OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0)
       );
       END Alu4;
     
ARCHITECTURE imp OF Alu4 IS
COMPONENT Alu1
PORT(a,b: IN STD_LOGIC;
      carryIn: IN STD_LOGIC;
      control: IN STD_LOGIC;
      result: OUT STD_LOGIC;
      carryOut: OUT STD_LOGIC;
      );
      END COMPONENT;
SIGNAL carry_sig: STD_LOGIC_VECTOR(N DOWNTO 0); --carry_sig(N) = MSB carryOut
SIGNAL result_sig: STD_LOGIC_VECTOR(N-1 DOWNTO 0);
BEGIN

      --Dont understand where to begin and how to name my parameters.
      -- suppose to use generate ...port map
END imp;

if you need the 1bit alu, here it is

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

ENTITY Alu1 IS
   PORT(a,b: IN STD_LOGIC;
        CarryIn: IN STD_LOGIC;
        control: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
        result: OUT STD_LOGIC;
        carryOut: OUT STD_LOGIC
        );
END Alu1;
      
ARCHITECTURE imp OF Alu1 IS
COMPONENT Adder1
PORT(a,b: IN STD_LOGIC;
       cIn: IN STD_LOGIC;
       sum: OUT STD_LOGIC;
       cOut: OUT STD_LOGIC);
END COMPONENT;
SIGNAL a_sig, b_sig: STD_LOGIC;
SIGNAL sum_sig, carryOut_sig: STD_LOGIC;
SIGNAL result_sig: STD_LOGIC;
      
BEGIN
a_sig <= a;
b_sig <= NOT b WHEN control = "11" ELSE       --SUBTRACT (1'S COMPLEMENT)
           b;
co: Adder1 PORT MAP(a_sig, b_sig, carryIn, sum_sig, carryOut_sig);


          --ADD and SUBTRACT operations do the same thing(ADD).
WITH control SELECT
result_sig <=
   a AND b WHEN "00", --AND
    a OR b WHEN "01", --OR
    sum_sig WHEN "10", --ADD
   sum_sig WHEN "11"; --SUBTRACT
  
   result<= result_sig;
              --carryOut= "0" when AND or OR operations
   carryOut <= '0' WHEN control = "00" OR control="01" ELSE
               carryOut_sig;
                        
END imp;

Problem Description You are required to create a 4-bit Arithmetic Logic Unit (ALU) in VHDL. ALU is a digital circuit that performs arithmetic and logical operations. The ALU logic block Diagram and its operations shown as following:

Explanation / Answer

i think you are looking for formatting the above...

hope this wil helps you..

<p><img alt="" src="//d2vlcm61l7u1fs.cloudfront.net/media%2F6db%2F6db78bb1-9c98-431a-b2f2-6b28234c3fec%2FphpXVSNIH.png" />You need to demonstrate logical operations (AND and OR) and arithmetic operations (Add, Subtract). This 4-bit ALU uses the toggle switches as the inputs (4-bit a, 4-bit b, and 2-bit control lines).</p>
<p>&nbsp;</p>
<p>LIBRARY IEEE;
    <br /> USE IEEE.STD_LOGIC_1164.ALL;</p>
<p>ENTITY Alu4 IS
    <br /> GENERIC(CONSTANT N: INTEGER:=4;&nbsp;&nbsp;&nbsp; --4 BITS ALU
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONSTANT Z: STD_LOGIC_VECTOR(3 DOWNTO 1):="000" --3 ZEROs
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );
    <br /> PORT(a,b: IN STD_LOGIC_VECTOR(N-1 DOWNTO 0);
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; control: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; overflow: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zero: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; carryOut: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result: OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0)
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END Alu4;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br /> ARCHITECTURE imp OF Alu4 IS
    <br /> COMPONENT Alu1
    <br /> PORT(a,b: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; carryIn: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; control: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; carryOut: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END COMPONENT;
    <br /> SIGNAL carry_sig: STD_LOGIC_VECTOR(N DOWNTO 0); --carry_sig(N) = MSB carryOut
    <br /> SIGNAL result_sig: STD_LOGIC_VECTOR(N-1 DOWNTO 0);
    <br /> BEGIN
    <br />
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --Dont understand where to begin and how to name my parameters.
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- suppose to use generate ...port map
    <br /> END imp;</p>
<p>if you need the 1bit alu, here it is</p>
<p>LIBRARY IEEE;
    <br /> USE IEEE.STD_LOGIC_1164.ALL;</p>
<p>ENTITY Alu1 IS
    <br /> &nbsp;&nbsp; PORT(a,b: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CarryIn: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; control: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; carryOut: OUT STD_LOGIC
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );
    <br /> END Alu1;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br /> ARCHITECTURE imp OF Alu1 IS
    <br /> COMPONENT Adder1
    <br /> PORT(a,b: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cIn: IN STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum: OUT STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cOut: OUT STD_LOGIC);
    <br /> END COMPONENT;
    <br /> SIGNAL a_sig, b_sig: STD_LOGIC;
    <br /> SIGNAL sum_sig, carryOut_sig: STD_LOGIC;
    <br /> SIGNAL result_sig: STD_LOGIC;
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br /> BEGIN
    <br /> a_sig &lt;= a;
    <br /> b_sig &lt;= NOT b WHEN control = "11" ELSE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --SUBTRACT (1'S COMPLEMENT)
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b;
    <br /> co: Adder1 PORT MAP(a_sig, b_sig, carryIn, sum_sig, carryOut_sig);</p>
<p>
    <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --ADD and SUBTRACT operations do the same thing(ADD).
    <br /> WITH control SELECT
    <br /> result_sig &lt;=
    <br /> &nbsp;&nbsp; a AND b WHEN "00", --AND
    <br /> &nbsp;&nbsp;&nbsp; a OR b WHEN "01", --OR
    <br /> &nbsp;&nbsp;&nbsp; sum_sig WHEN "10", --ADD
    <br /> &nbsp;&nbsp; sum_sig WHEN "11"; --SUBTRACT
    <br /> &nbsp;&nbsp;
    <br /> &nbsp;&nbsp; result&lt;= result_sig;
    <br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; --carryOut= "0" when AND or OR operations
    <br /> &nbsp;&nbsp; carryOut &lt;= '0' WHEN control = "00" OR control="01" ELSE
    <br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; carryOut_sig;
    <br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br /> END imp;</p>