creating and ALU in verilog

Guest #4027818
Rate this post
• ▲ useful
▼ not useful
I was wondering if it were possible to have if statements as so for the 
ALU I am trying to build. I am passing values from a datapath test bench 
to a datapath, from the datapath into the ALU, and from the ALU back to 
the datapath. What i am trying to do is create a control unit which will 
only pass values through a certain component if the corresponding 
control_ALU is activated.

here is my verilog code :

module ALU (
 input en_ALU, clk_ALU,
input [31:0]  inputA, inputB, control_ALU,
output [31:0] resultc
);
wire [31:0] res_out;


always @(control_ALU)
begin
        if(control_ALU[1])  begin
    andLogic  andLogic_component(
                                            .dataA (inputA),
                                            .dataB(inputB) ,
                                            .resultA (res_out));
end



 if(control_ALU[2]) begin
negate m0(
.inputnegate    (inputA),
.resultnegate   (res_out)
);
    end
end

reg64bit z(.clk(clk_ALU) , .clr(clr), .enable(en_ALU), .inputd(res_out), 
.outputq(resultc));


endmodule
Guest #4033999
Rate this post
• ▲ useful
▼ not useful
Here is how i typically make ALU. I've done a number of custom 
processors this way.  Note : Verilog 2001 syntax and i do make use of 
command scheduling as per the official Verilog spec ( very few people 
know/use scheduling but all synthesizers support it : Quartuse, ISe , 
Synopsys )
1
module mini_alu( input [31:0] a,b ,
2
                 input [7:0] opcode,
3
                 input reset,
4
                 output [31:0] x )
5

6
`define opcNOP    8'd0
7
`define opcAND    8'd1
8
`define opcOR     8'd1
9
`define opcBWANDa  8'd2
10
`define opcBWANDb  8'd2
11

12
.... other opcodes
13

14
always_comb(begin)
15
case (opcode)
16
    `opcNOP : output = 32'h0;
17
    `opcAND : output = a & b;
18
    `opcBWANDa : output = &a;
19
     ....
20

21
    default :  output = 32'b0;
22
endcase
23
if (reset) output <= 32'hDEADBEEF
24
end
25

26
endmodule;
Guest #4034000
Rate this post
• ▲ useful
▼ not useful
vincent himpe wrote:

drat ! typo's fixed
> Here is how i typically make ALU. I've done a number of custom
> processors this way.  Note : Verilog 2001 syntax and i do make use of
> command scheduling as per the official Verilog spec ( very few people
> know/use scheduling but all synthesizers support it : Quartuse, ISe ,
> Synopsys )

module mini_alu( input [31:0] a,b ,
                  input [7:0] opcode,
                  input reset,
                  output [31:0] x )

 `define opcNOP    8'd0
 `define opcAND    8'd1
 `define opcOR     8'd2
 `define opcBWANDa  8'd3
 `define opcBWANDb  8'd4

 // .... other opcodes

> always_comb begin
 case (opcode)
     `opcNOP : output = 32'h0;
     `opcAND : output = a & b;
     `opcBWANDa : output = &a;
     // ....

     default :  output = 32'b0;
 endcase
 if (reset) output <= 32'hDEADBEEF
 end

 endmodule;
[/code]

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.