当前位置:网站首页>Alu logic operation unit

Alu logic operation unit

2022-07-05 05:28:00 Li Junfeng

ALU Logical unit of operation

according to ( Two ) Medium to single cycle CPU The definition of , This module needs to realize the following 4 Class operation : Add 、 reduce 、 Bitwise AND 、 Press bit or . Therefore need 2 bit The control signal of Aluc To control ALU Operation type of .
Correspondence of signals :
surface 4 1 Aluc Coding and corresponding functions
Aluc code Realization function Arithmetic type
00 Add Arithmetic operation
01 reduce Arithmetic operations
10 Bitwise AND Logical operations
11 Press bit or Logical operations
Addition and subtraction can be used 32 Bit full adder ADDSUB_32 Realization , Bitwise and used AND32, Bit by bit or used OR32, The choice of function uses 32 Bit two choose one multi-channel selector MUX2X32 Realization , Returned the result R, as well as ALU Whether the operation result of is 0 The judgment of the Z( if R=0,Z=1;),Z Mainly for beq、bne Instructions .

Code

  	module ALU(X,Y,Aluc,R,Z);  
  	    input [31:0]X,Y;  
  	    input [1:0] Aluc;  
  	    output [31:0]R;  
  	    output Z;  
  	    wire [31:0]d_as,d_and,d_or,d_and_or;  
  	    ADDSUB_32 as32(X,Y,Aluc[0],d_as);  
  	    AND32 a32(X,Y,d_and);  
  	    OR32 o32(X,Y,d_or);  
  	    MUX2X32 select1(d_and,d_or,Aluc[0],d_and_or);  
  	    MUX2X32 select2(d_as,d_and_or,Aluc[1],R);  
  	    isZero i1(R,Z);  
    	endmodule  

原网站

版权声明
本文为[Li Junfeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050527288037.html