EmbDev.net

Forum: FPGA, VHDL & Verilog Please help for 4-bit ALU


Author: peres Z. (peres_z)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hi all!

I am trying to make a 4 bit ALU. Here is a sample entity declaration:

entity myALU is
  Port ( Opcode : in  STD_LOGIC_VECTOR (2 downto 0);
         Ain, Bin : in  STD_LOGIC_VECTOR (3 downto 0); --Operand 1 and 2
         Cin : in  STD_LOGIC;  -- carry in
         Output : out  STD_LOGIC_VECTOR (3 downto 0);
         Zero : out  STD_LOGIC;
         Co : out  STD_LOGIC
        );
end myALU;


The ALU should perform the following operations according to the Opcode:


Opcode  |  Operation  |  Output     |  Carry Out(Co)  |
000     |    NOP      |     A       |    0
001     |    AND      |   A & B     |    0
010     |    OR       |   A or B    |    0
011     |   XOR       |   A xor B   |    0
100     |  ADD        |   A + B     |'1' if (A + B) > $F, else '0'
101     |  ADC        |   A+B+Cin   |'1' if (A + B + Cin) > $F else '0'
110     |  SUB        |  |A - B|    |'1' if (A < B), else '0'
111     |  SBC        | |Cin + A-B| |'1' if (A + Cin) < B, else '0'

[Zero <= '1' if Output is 0, else '0']


Can someone please help me write a VHDL code for that ALU,
You can find attached the code that I have written but it doesn't work 
and I am consfused.

Thank you.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
WHAT does not work with your description?
WHAT errors do you get?

Author: Daniel M. (daniel__m)
Posted on:

Rate this post
0 useful
not useful
At least the sensitivity-list is incomplete. The simulator will not show 
the real behaviour.

greetings

Author: PittyJ (Guest)
Posted on:

Rate this post
0 useful
not useful
I do not find a clock.

At this stage you should write a testbench, where you put some input 
signals into the ALU and look what happens.

Author: peres Z. (peres_z)
Posted on:

Rate this post
0 useful
not useful
I did it but I have wrong values

Author: PittyJ (Guest)
Posted on:

Rate this post
0 useful
not useful
Can you please also post your testbench code?
Maybe there is the error?

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
peres Z. wrote:
> I did it but I have wrong values
WHAT values?
For help you MUST provide as much information as possible. Who do you 
think can help when you say: "My car doesn't run! Whats wrong with it?"

And think again about this what Daniel M. wrote:
>> At least the sensitivity-list is incomplete.
Z, Cin and Cx is missing! And because of the missing Z you will see some 
very very strange bahviour...

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.