How to Implement an ALU at Gate Level in Verilog?

  • Thread starter Thread starter alt3r
  • Start date Start date
  • Tags Tags
    Alu
AI Thread Summary
To implement an ALU at gate level in Verilog, set up three registers: an instruction control register, an accumulator (Register A), and a second register (Register B) of the same size as A. The control register dictates the operation, with specific binary codes corresponding to functions like AND, OR, and others. The implementation involves IF-THEN statements that execute logic operations based on the control register's value. For more complex operations, consider expanding the control register or adding additional registers to avoid complications. This foundational approach can lead to more advanced designs, such as microprocessors.
alt3r
Messages
1
Reaction score
0
Hello guys,
i want ALU implemented in gate level in verilog, please help me
 
Engineering news on Phys.org
That's a pretty standard simple exercise.

Just set up three registers (or bit-level flip-flops) for the number of bits that you wish to deal with.

1. Instruction control register - Usually just 3 or 4 bits wide
2. Register A (for accumulator) - Might be 8, 16, 32, or whatever you want
3. Register B - Must be the same size as register A

Then just write the code based on the contents of the control register.

In other words, if the control register contains say 000 then have Register B AND with register A leaving the result in A.

If the control register contains say 001 then have register B OR with register A leaving the resultes in A.

You can do similar things with various binary codes in your control register.

It's a pretty simple routine. Once you have the three registers defined, the rest is just IF THEN statements of the form:

IF control=000 THEN A = B LOGIC A
IF control=001 THEN A = B LOGIC A
IF control=010 THEN A = B LOGIC A
IF control=011 THEN A = B LOGIC A
IF control=100 THEN A = B LOGIC A
IF control=001 THEN A = B LOGIC A

Where "LOGIC" is something like AND, OR, NOT, ADD, SUB, ect.

And so on. If you need more control make the control register 4-bits wide or wider.

You might also want to implement a carry flag, or other types of flags. Keep going and the next thing you know you'll be designing a microprocessor!

Hope this helps. You'll still have to work out the actual syntax and initial register set up, but if you are taking a course in this that part should be relatively straight-forward.

Here's a link to a similar assignment, it doesn't give the answer but by it might be helpful:

http://www.u-aizu.ac.jp/~yliu/teaching/comparch/lab1.html
 
By the way, using A as both the accumulator and one of the initial registers can sometimes be a bit tricky with some HDL. If you have problems with that you might try adding yet another register say D and write the code as follows

IF control=000 THEN D = B LOGIC A
IF control=001 THEN D = B LOGIC A
IF control=010 THEN D = B LOGIC A
IF control=011 THEN D = B LOGIC A
IF control=100 THEN D = B LOGIC A
IF control=001 THEN D = B LOGIC A

This way you will be guaranteed good results without the possibiliy of causing a closed loop. It's actually been a while since I've done any HDL so maybe others will respond with some better ideas.
 
While I was rolling out a shielded cable, a though came to my mind - what happens to the current flow in the cable if there came a short between the wire and the shield in both ends of the cable? For simplicity, lets assume a 1-wire copper wire wrapped in an aluminum shield. The wire and the shield has the same cross section area. There are insulating material between them, and in both ends there is a short between them. My first thought, the total resistance of the cable would be reduced...
Hi all I have some confusion about piezoelectrical sensors combination. If i have three acoustic piezoelectrical sensors (with same receive sensitivity in dB ref V/1uPa) placed at specific distance, these sensors receive acoustic signal from a sound source placed at far field distance (Plane Wave) and from broadside. I receive output of these sensors through individual preamplifiers, add them through hardware like summer circuit adder or in software after digitization and in this way got an...
I am not an electrical engineering student, but a lowly apprentice electrician. I learn both on the job and also take classes for my apprenticeship. I recently wired my first transformer and I understand that the neutral and ground are bonded together in the transformer or in the service. What I don't understand is, if the neutral is a current carrying conductor, which is then bonded to the ground conductor, why does current only flow back to its source and not on the ground path...
Back
Top