aboutsummaryrefslogtreecommitdiff
path: root/hdl/alu_ctrl.v
blob: 1a68d2c138aa56d7d7f3bb09698d1aecbc56cbd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
`timescale 1ns / 1ps

/**
ALU Control unit
 */
module alu_ctrl( input      [1:0] alu_op,
                 input      [5:0] func_code,
		       output reg [4:0] alu_ctl );
   
     always @* begin
          if(alu_op == 0)       
               alu_ctl = 2;             // add      
          else if(alu_op == 1)  
               alu_ctl = 6;      
          else case( func_code )
               32: alu_ctl = 2;	     // add
               34: alu_ctl = 6;	     // subtract
               36: alu_ctl = 0;	     // and
               37: alu_ctl = 1;	     // or
               38: alu_ctl = 9;	     // xor
               39: alu_ctl = 8;	     // nor
               42: alu_ctl = 7;	     // slt
               default: alu_ctl = 15;   // should not happen
          endcase
     end
   
endmodule