- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
习题 3
三、写出下面 Verilog 程序的执行结果
1、下面程序执行完后,写出 A,B,C,D,clk 的结果
module adder_1(A,B,C,D,clk);
input clk;
input[7:0] A, B ;
output[7:0] C , D ;
reg[7:0] C, D ;
initial
begin
A=8`
B=8`
clk=1
end
always@(clk)
begin
C=A+B;
If (A+B>255) D[3]=1`b1;
else D[3]=0;
end
endmodule
2、下面程序执行完后,写出 count 的结果
module counter(tempreg, count);
input tempreg;
output count;
reg [7: 0] tempreg;
reg [3: 0] count;
initial
begin
count = 0;
tempreg=8`b0111010
end
while (tempreg)
begin
if (tempreg[ 0]) count = count + 1;
tempreg = tempreg >> 1;
end
endmodule
3、下面程序执行完后,写出 factorial 的结果
module try_factorial;
function automatic integer factorial;
input [31:0] operand;
integer i;
if (operand>=2)
factorial=factorial(operand-1)*operand;
else
factorial=1;
endfunction
integer result;
integer n;
initial
begin
for(n=0;n<=7;n=n+1)
begin
result=factorial(n);
$display("%0d factorial=%0d",n,result);
end
end
endmodule
4 、下面程序执行完后,写出 out1/out2 的结果
module check(A, clk, out1, out2);
input A[0:7], clk;
output out1, out2;
initial
begin
clk=1`b1;
A=8`
end
always@(clk)
begin
out1=|A
out2=A[0];
end
endmodule
5、下面程序执行完后,写出 A 、B、C 的结果
module con (A,B,C);
reg[0:7] A, B;
reg C;
initial
begin
#9; $stop;
end
initial A=0;B=0;
always
文档评论(0)