下载此文档

设计一个带控制端的逻辑运算电路分别完成正整数的平方、立方和阶乘的运算.doc


文档分类:通信/电子 | 页数:约4页 举报非法文档有奖
1/4
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/4 下载此文档
文档列表 文档介绍
练****设计一个带控制端的逻辑运算电路,分别完成正整数的平方、立方和阶乘的运算。
//--------------myfunction----------
module myfunction(clk,n,result,reset,sl);
output[6:0] result;
input[2:0] n;
input reset,clk;
input [1:0] sl;
reg[6:0] result;//define input and output
always @(posedge clk)
begin
if(!reset)
result<=0;
else
begin
case(sl)
2'd0: result<=square(n);
2'd1: result<=cubic(n);
2'd2: result<=factorial(n);
endcase
end
end
function[6:0] square;
input [2:0] operand;
begin
square=operand*operand;
end
endfunction
function[6:0] cubic;
input [2:0] operand;
begin
cubic=operand*operand*operand;
end
endfunction
function[6:0] factorial;
input [2:0] operand;
reg [2:0] index;
begin
factorial = 1 ;
for(index = 2; index <= operand; index = index + 1)
factorial = index * factorial;
end
endfunction
endmodule
//--------------testmyfunc----------
`include "./"
`timescale 1ns/100ps
`define clk_c

设计一个带控制端的逻辑运算电路分别完成正整数的平方、立方和阶乘的运算 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数4
  • 收藏数0 收藏
  • 顶次数0
  • 上传人镜花流水
  • 文件大小23 KB
  • 时间2018-10-30