日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

带控制端的逻辑运算电路_分别完成正整数的平方、立方和阶乘的运算verilog语言...

發布時間:2025/3/8 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 带控制端的逻辑运算电路_分别完成正整数的平方、立方和阶乘的运算verilog语言... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

練習:設計一個帶控制端的邏輯運算電路,分別完成正整數的平方、立方和階乘的運算。

//--------------myfunction----------

modulemyfunction(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 @(posedgeclk)

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"./myfunction.v"

`timescale1ns/100ps

`define clk_cycle50

module testmyfunc;

reg[2:0] n;

reg reset,clk;

reg[1:0] sl;

wire[6:0] result;

parametertimes=20;

initial

begin

n=0;

reset=1;

clk=0;

sl=0;

?

#100 reset=0;

#100 reset=1;

repeat(times)

begin

#50sl={$random}%3;

#50 n={$random}%6;

end

#1000 $stop;

end

always #`clk_cycleclk=~clk;

myfunctionmyfunct(.clk(clk),.n(n),.result(result),.reset(reset),.sl(sl));

endmodule

總結

以上是生活随笔為你收集整理的带控制端的逻辑运算电路_分别完成正整数的平方、立方和阶乘的运算verilog语言...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。