zoukankan      html  css  js  c++  java
  • 计算机组成原理实验_算术逻辑运算器的实现

    module alu(x, y,instruction,overflow,result);
    	parameter bit_width=4;
    	input [bit_width-1:0]x,y;
    	input [2:0] instruction;
    	output overflow;
    	output [bit_width-1:0] result;
    	reg [bit_0] temp;
    	reg [bit_width-1:0] result;
    	reg overflow;
    	initial 	
         overflow=0;
      always@ (x or y or instruction)
    	begin  case (instruction)
    		  3'b001:begin temp = {x[bit_width-1], x}+{y[bit_width-1],y};
    			     result <= temp[bit_width-1 :0]; 
    			     overflow <= temp[bit_width] ^ temp[bit_width-1];
    			   end  // 当输入为001的情况时的加功能为:result<=x+y;
      
            /********** Begin *********/
    		 3'b010:begin temp = {x[bit_width-1], x}-{y[bit_width-1],y};
    			     result <= temp[bit_width-1:0]; 
    			     overflow <= temp[bit_width] ^ temp[bit_width-1];
    			   end
            /********** End *********/  // 请补全上面为*的代码,实现当输入为010的情况时的减功能为:result<=x-y;
    		  
    		  3'b011:begin  result <= x&y; end
    		  3'b100:begin  result <= x|y; end
    		  3'b101:begin  result <= x^y; end
    		  3'b110:begin  result <= {1'b0,x[bit_width-1:1]}; end //实现逻辑右移1位
    
    		  3'b111:begin  result <= x << 1; end //补全该行代码,实现逻辑左移1位。
    		  default:begin result <= 0; overflow <=0; end
    		endcase   
           end   
    endmodule
    
    作者:LightAc
    出处:https://www.cnblogs.com/lightac/
    联系:
    Email: dzz@stu.ouc.edu.cn
    QQ: 1171613053
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    python之访问限制机制
    python之property装饰器
    python之封装、组合
    python中classmethod和staticmethod
    (专题一)01 matlab基础
    代数运算
    点运算
    研究生学习安排2019/6/6
    图像处理中创建CDib类时无法选择基类类型时怎么办
    04 学习java养成良好的写作习惯
  • 原文地址:https://www.cnblogs.com/lightac/p/12886229.html
Copyright © 2011-2022 走看看