⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alu.v

📁 以前在学校里的课程设计
💻 V
字号:
module ALU(ALU_O,ALU_C,C_in,op,AC_in,GR_in);

  output ALU_C;               
  output [7:0] ALU_O;   
  input  C_in;                
  input  [4:0] op;           
  input  [7:0] AC_in;  
  input  [7:0] GR_in;   

  
  
  reg    [7:0] ALU_O;   
  reg    ALU_C;

  always @(C_in or op or AC_in or GR_in)
         begin
	    case (op)
	      5'b00011:                                                 
	               begin {ALU_C,ALU_O}={C_in,AC_in};end//AC->RI              
      	      5'b00100:
      	               begin {ALU_C,ALU_O}={C_in,GR_in};end //RI->AC                                                
              5'b00111:
                       begin {ALU_C,ALU_O}=AC_in+GR_in;end              
	      5'b01000:					                 
	               begin {ALU_C,ALU_O}=AC_in-GR_in;end        
	      5'b01011:
	               begin {ALU_C,ALU_O}=AC_in+GR_in+C_in;end          
	      5'b01100:
	               begin {ALU_C,ALU_O}=AC_in-GR_in-C_in;end         

              5'b01111:
                       begin {ALU_C,ALU_O}={C_in,~GR_in};end//~RI            
              5'b10000:
                       begin {ALU_O,ALU_C}={C_in,GR_in};end //SHCR AC,RI             
	      5'b10001:
	               begin {ALU_C,ALU_O}={GR_in,C_in};end //SHCL AC,RI
	      5'b11100:
	               begin {ALU_C,ALU_O}={C_in,mul(AC_in[3:0],GR_in[3:0])};end 
	      5'b11101:
	               begin {ALU_C,ALU_O}={C_in,div(AC_in[7:0],GR_in[7:0])};end                            	      
	      default:begin  {ALU_C,ALU_O}={C_in,ALU_O};end            
	    endcase
         end
function [7:0] mul;
   input [3:0]AC_in;
   input [3:0]GR_in;
   reg [7:0]R;
   reg [7:0]temp;
   reg [7:0]temp2;
   begin
        
    R=0;
    temp=0;
    temp2=AC_in;
        
    if(GR_in[0]==1)
    begin
      temp=temp2;
      R=temp2;
      temp2=temp;
    end
    
    if(GR_in[1]==1)
    begin
      temp=temp2;
      R=R+(temp2<<1);
      temp2=temp;
    end
    
    if(GR_in[2]==1)
    begin
      temp=temp2;
      R=R+(temp2<<2);
      temp2=temp;
    end
    
    if(GR_in[3]==1)
    begin
      temp=temp2;
      R=R+(temp2<<3); 
      temp2=temp;
    end 
    
    mul=R;
     
   end
 endfunction   


function [7:0]div;
  input [7:0]AC_in;
  input [7:0]GR_in;
  reg [7:0]R_out;
  reg [7:0]temp;
  reg [7:0]temp2;
  reg [7:0]temp3;
  reg [7:0]next;
  reg [7:0]temp4;
  
   begin
      		R_out=8'b0;      
      		temp=AC_in;
      		next=8'b0;
      		temp3=8'b0;
      		temp2=GR_in;
    	        temp4=AC_in;
    		if(AC_in<GR_in)
      			R_out=8'b0;
    		else    			
    		if(AC_in==GR_in)
      		  R_out=8'b1;
    	else
      	begin
      	
        	next=temp;
        	temp=temp>>7;
        	if(temp>=GR_in)
          	begin
               temp3=temp2;
               R_out[7]=1'b1;
            temp=temp4-(temp2<<7);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end
         temp=next;
       
        
        next=temp;   
        temp=temp>>6;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[6]=1'b1;
            temp=temp4-(temp2<<6);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end        
         temp=next; 
        
       next=temp;
       temp=temp>>5;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[5]=1'b1;
            temp=temp4-(temp2<<5);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end
       temp=next;  
     
       next=temp;
       temp=temp>>4;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[4]=1'b1;
            temp=temp4-(temp2<<4);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end 
         temp=next;   
       
      next=temp;
      temp=temp>>3;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[3]=1'b1;
            temp=temp4-(temp2<<3);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end 
         temp=next;  
       
       next=temp;
       temp=temp>>2;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[2]=1'b1;
            temp=temp4-(temp2<<2);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end 
         temp=next;  
        
      next=temp; 
      temp=temp>>1;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[1]=1'b1;
            temp=temp4-(temp2<<1);
            temp2=temp3;
            next=temp;
            temp4=temp;
          end 
         temp=next;   
       
      next=temp;   
      temp=temp;  
        if(temp>=GR_in)
          begin
            temp3=temp2;
            R_out[0]=1'b1;
            temp=temp4-temp2;
            temp2=temp3;
            next=temp;
            temp4=temp;
          end
        temp=next;     
     
     div=R_out;
      end  
      
  end
endfunction            
endmodule
//???????????????       
      
        
        
        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -