首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

编译预处理语句 if-else语句

编译预处理语句 if-else语句

程序:

1:  8位全加器

              module adder8 ( cout,sum,a,b,cin );  

                  output cout;             // 输出端口声明

                  output [7:0] sum;

                  input [7:0] a,b;           // 输入端口声明

                  input   cin;                       

                  assign {cout,sum}=a+b+cin;      

              endmodule


2:  8位计数器

              module counter8 ( out,cout,data,load, cin,clk );      

                  output [7:0] out;

                  output  cout;                    

                  input [7:0] data;                 

                  input load, cin,clk ;                           

                  reg[7:0] out;

                  always @(posedge clk)

                     begin

                          if(load)

                      out <= data;                     // 同步预置数据

                         else

                       out < = out + 1 +  cin;     // 1计数

                     end

                assign cout = &out & cin;  //out8hFFcin1,则cout1

              Endmodule

3:描述的7人投票表决器:若超过4人(含4人)投赞成票,则表决通过。

module  vote7 (pass,vote );      

      outputpass;

      input[6:0] vote;                             

      reg[2:0]sum;      //sumreg型变量,用于统计赞成的人数

      integer i;

      reg pass;

      always@(vote)

          begin

             sum = 0;                                    //sum初值为0

             for(i = 0;i<=6;i = i+1)               //for语句

           if(vote)      sum = sum+1;

                                                 //只要有人投赞成票,则 sum1

             if(sum[2])     pass = 1;  //若超过4人赞成,则表决通过 else                 pass = 0;

         end

endmodule

4:实现41数据选择器.

返回列表