1.设计一个8位计数器,每次时钟_上升沿时计数加1,当计数器溢出时,自动从0开始重新计数。
复制代码
1
2
3
4
5
6
7
8
9module count8(clk,count); input clk; output reg[7:0] count; always@(posedge clk) begin count = count + 1; end endmodule
2.分别用任务和函数描述一个4选1多路选择器。
函数:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15function mul_4; //默认返回1位reg 类型,如需返回其他类型,需要指明 input[1:0] ss; inout s1,s2,s3,s4; // 主体开始部分 begin case(ss) 2'b00 : mul_4 = s1; /// 函数名就是函数的返回值 2'b01 : mul_4 = s2; 2'b10 : mul_4 = s3; 2'b11 : mul_4 = s4; endcase end endfunction
任务:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14task mul_4; intput[1:0] ss; input s1,s2,s3,s4; output out; begin case(ss) 2'b00 : out = s1; 2'b01 : out = s2; 2'b10 : out = s3; 2'b11 : out = s4; endcase end endtask
3.试编写求补码的verilog程序,输入是带符号的8位二进制数。
由于是带符号的二进制数,所以需要分非负 负两种情况。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12module test(in,out); input[7:0] in; output reg[7:0] regout; always@(in) begin if( ~in[7] ) out = in; else out = (~in+1) | 8'b10000000; end endmodule
4.试编写两个4位二进制数相减的verilog程序。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24module (ina,inb,out); input[3:0] ina,inb; output reg[4:0] out; function[3:0] abs input[3:0] a; begin if ~ina[3] abs = a; else abs = ~a + 1; endfunction always@(ina,inb) begin case({ina[3],inb[3]} 2'b00:out = abs(ina) - abs(inb); 2'b01:out = abs(ina) + abs(inb); 2'b10:out = -abs(ina) - abs(inb); 2'b11:out = -abs(ina) + abs(inb); endcase end endmodule
5.写- -个比较电路,当输入的- -位8421BCD码大于4时,输出为1,否则为0。试编写出verilog程序。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12module test(in,out); input[3:0] in; output reg out; always@(in) begin if (i>4) out = 1; else out = 0; end endmodule
最后
以上就是疯狂枕头最近收集整理的关于EDA 课堂练习2的全部内容,更多相关EDA内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复