1

I am currently studying an electrical engineering degree and have designed a 4 bit ALU as part of an assignment.

I have been asked how I could easily convert it to an 8 bit ALU. My answer currently stands that I would alter all of the modules (add, sub, bux, or, xor LS, RS, etc.) to 8 bit ones as well as the switch numbers for the FPGA board in the ALU module.

Is this the easiest way or would I be able to design the ALU to call on each 4 bit gate twice or add the 4 bit modules a second time with a diferent name?

I feel as though I have exhausted my textbooks and the net which is frustrating as the information must be out there!

I am using Quartus II to program.

B.Realey
  • 19
  • 2
  • 1
    "have been asked" suggests this may be an assignment. You have described three ways, they all work and I've seen them all used. Each has its advantages and disadvantages, I suggest you elaborate on these. in your assignment or report. –  Mar 17 '16 at 15:00
  • 1
    Ask about specific problems converting your your existing implementation. The *easiest way* is subjective, your readers don't have sufficient detail and answers would be opinion without factual basis. –  Mar 17 '16 at 17:39
  • The easiest way may be to use a generic implementation, but this depends on your definition of _easiest_. Or do you actually need help on composing it out of 4-bit ALUs? Also your title, does not match your description. – Martin Zabel Mar 17 '16 at 22:28

1 Answers1

0

The actual answer depends on the actual ALU you have and the method you choose. You say you have tried to find how to connect two 4-bit ALUs; here is some help:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.defs_pkg.all;

entity cpu_alu is
  port(
    opA     :  in std_logic_vector(15 downto 0);  -- operand A
    opB     :  in std_logic_vector(15 downto 0);  -- operand B
    Op      :  in std_logic_vector(2 downto 0);   -- operator
    cIn     :  in std_logic;                      -- carry in
    invA    :  in std_logic;                      -- invert A
    result  : out std_logic_vector(15 downto 0);  -- result
    cOut    : out std_logic;                      -- carry out
    overflow: out std_logic;                      -- overflow
    zero    : out std_logic
  );
end entity cpu_alu;

architecture rtl1 of cpu_alu is

  signal A: std_logic_vector(7 downto 0);

  signal INTERNAL_CARRY: std_logic;    -- the carry chain
  signal zeroMSB: std_logic;           -- because this ALU has a 'zero' output
  signal zeroLSB: std_logic;

  constant Top : integer := A'left;

begin

    MSB : entity work.cpu_alu8
    port map ( opA    => opA(7 downto 0), 
               opB    => opB(7 downto 0), 
               Op     => Op,
               CIn    => CIn,
               invA   => inVa,
               result => result(7 downto 0), 
               cout   => INTERNAL_CARRY,
               overflow => open,
               zero => zeroMSB);

    MSL : entity work.cpu_alu8
    port map ( opA    => opA(15 downto 8), 
               opB    => opB(15 downto 8), 
               Op     => Op,
               CIn    => INTERNAL_CARRY,
               invA   => inVa,
               result => result(15 downto 8), 
               cout   => cOut,
               overflow => overflow,
               zero => zeroLSB);

    zero <= zeroMSB and zeroLSB;

end architecture rtl1; -- of cpu_alu

This shows two 8-bit ALUs connected together to make one 16-bit ALU. I already had a 16-bit ALU prepared earlier, so I converted it to an 8-bit ALU and instantiated it twice to make the original 16-bit ALU (so I could run the same test on it to make sure I had done it correctly*). I'm sure you can convert it to 2x 4-bit ALU.

The 8 LSBs go to the first ALU; the 8 MSBs go to the second. The key thing to see is how I have connected the carry output of the first ALU to the carry input of the second. Notice also that I am not interested in the overflow output from the LSB ALU. Finally, I needed to combine the zero output from each.

Now, of course, I don't know what your ALU actually does. This one doesn't do much; the only mathematical operation it does is ADD. (It's an answer to an exercise and for that reason I am not going to post all the code).

*That is what you should always do. You mention Quartus. Quartus doesn't simulate - it starts with synthesis. You should always simulate before synthesising: it is much quicker to find bugs, find their source and fix them.

Matthew Taylor
  • 13,365
  • 3
  • 17
  • 44
  • *You say you have tried to find how to connect two 4-bit ALUs ...* This assertion doesn't appear to be supported by the question or it's edit history. –  Mar 17 '16 at 17:43
  • Converting your code to an instantiation of two 4-bit ALUs may be possible, but it would be helpful to document the ports. For example, what is `invA`? The last paragraph depends on whether you see ModelSim Altera Edition as part of Quartus or not. – Martin Zabel Mar 17 '16 at 22:25
  • @user1155120 _I_ haven't done any of those things. The poster of the question says he has. – Matthew Taylor Mar 18 '16 at 06:01
  • @Martin Zabel I have added labels for the I/O. To be honest, I think I have documented what was important to answer the question. I don't see Modelsim as being part of Quartus - it's a completely separate EDA tool. Not bothering to simulate seems to be common in the FPGA community: I see it here, I see it with the people I teach. I am just pointing out that it is better to simulate first. – Matthew Taylor Mar 18 '16 at 06:04
  • " I would alter" or "or would I be able to design the ALU to call on each 4 bit gate twice" appears to be future tense. In any event the question isn't specific and your answer can't be. –  Mar 18 '16 at 06:18
  • @user1155120 As a new boy round here, I do want to fit in with the culture and do appreciate the long term benefits of keeping the quality high. Many times I have googled something and a Stack Overflow answer has come top and, having followed it, my problem has been solved. Having said that, it does seem an unfriendly place to a newbie. It seemed like a good question to me. I voted it up. He said he had tried to find the answer himself. And, in answering it, I learned something myself. – Matthew Taylor Mar 18 '16 at 09:11