# Homework Help: Designing a 4 bit ALU

1. Oct 20, 2008

### Random89

1. The problem statement, all variables and given/known data
A 4-bit arithmetic and logic unit (ALU) is to be designed for a 4-bit microprocessor.
The ALU has two 4-bit wide inputs, labelled ii and i2 and a 4-bit output labelled
out. In addition there is a carry-out bit. Design the ALU so that it implements the
following functions:
• add: out = i1 + i2
• subtract: out = i1 − i2
• shift-left: out = i1 shifted-left by 1-bit
• shift-right: out = i1 shifted-right by 1-bit
• transfer: out = i1

2. Relevant equations

3. The attempt at a solution
This was a question from a uni Tutorial sheet (not assessed, but relevent to assignments later on) which I got really stuck on. I have no idea how to even start it. Has anyone got any hints for how to get started so I can at least have an idea what I am dealing with as the lecture notes aren't great and the course texts make as much sense as if they were in Spanish. I understand logic gates, truth tables and that lot it is just fitting that in to this question is doing me in.
Any help would be great (but please don't just post the solution, I want to work this out).

2. Oct 21, 2008

### Random89

Has anyone got any idea? This is getting urgent now as the Assignment will be posted some time this week and I want to know what to do before it is posted.
Thanks

3. Oct 22, 2008

### waht

Are you familiar with shift registers?

4. Oct 22, 2008

### Random89

I am familiar with Flip-flops and after looking up shift registers it seems to lead on as they are made from a series of flip-flops.

5. Oct 22, 2008

### waht

Yea, a shift register is composed of a series of flip flops. Two primary functions of a shift register is to temporarily store a word, in your case it would be 4 bits, the second function is to shift the bits. More complex shift registers can shift the bits to the left or right.

This is basically half of your ALU.

6. Oct 22, 2008

### Random89

Ah okay, I get the idea. I have searched through the lecture notes and found something that might be the same idea. Now to learn how to use it in Quantus. Thanks for the help, going to spend about 7 hours in a lab tomorrow getting it working.

7. Oct 23, 2008

### Random89

Sorry to do this but I have got stuck again.
Firstly for some reason my Subtraction circuit is bringing up errors (I am using Quartus) for no reason (picture below).
Secondly I have built the circuit but I have no idea where to go from here, how to turn it into what is below into a full ALU. Anyone got any good tutorials for Quartus on how to do this? (first time using Quartus for me).
Lastly I need to use flags (or Status Bits) for Zero, Overflow and Negative. Can anyone understand this as I couldn't find it in the lecture notes?

Thanks for all the help so far. Everything I have so far is below, I have it in Quartus file type as well if anyone wants to have a closer look (let me know).

Oh and also we are only meant to use primative Logic gates, that is why I didn't use a Shift Register.
Transfer:
Subtraction (doesn't work):
Right Shift (1 place):
Left Shift (1 place):
Full ALU:

8. Oct 23, 2008

### waht

Subtracting works by adding a complement of one operand to another. That means you need to put an inverter at one of the inputs of the adder.

As far as shifting bits, are you allowed to use flip-flop?

9. Oct 23, 2008

### Random89

Nope, only basic logic gates like AND, OR, NOT, XOR etc.

10. May 27, 2009

### Cindy2009

Hello.....i have some question to ask.....i am interested in designing a 4 bits ALU that can perform calculations.Is there any info that can help to built up some knowledge abt ALU? Thanks...