找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2532|回复: 0
收起左侧

modelsim 编写Alu函数程序

[复制链接]
ID:126816 发表于 2016-6-15 11:19 | 显示全部楼层 |阅读模式
module ALU (A,B,control,c);
  input [7:0]A;
  input [7:0]B;
  input [1:0]control;
  
  output reg[15:0]c;
  
  function[15:0]ADD;
    input[7:0]A,B;
    begin
      ADD=A+B;
    end
  endfunction
  
  function[15:0]SUB;
    input[7:0]A,B;
    begin
      SUB=A-B;
    end
  endfunction
  
  function[15:0]MUT;
    input[7:0]A,B;
    begin
      MUT=A*B;
    end
  endfunction
  
  function[15:0]DIV;
    input[7:0]A,B;
    begin
      DIV=A/B;
    end
  endfunction
  
  always@(*)
  if(control==2'b00)
    c=ADD(A,B);
  else if(control==2'b01)
    c=SUB(A,B);
  else if(control==2'b10)
    c=MUT(A,B);
  else if(control==2'b11)
    c=DIV(A,B);
   
endmodule









激励自己写,很简单的。
  
  
  

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表