conditional statement

case statement

1. conditional statement

    if(expression)

        statement_or_null[else statement_or_null]

    | if_else_if_statement

If the expression evaluates to true(that is ,has a nonzero know value),the first statement shall be executed.

If it evaluates to flase(that is ,has a zero value or the value is x or z) , the first statement shall not execute.

If there is an else statement and expression is false , the else statement shall be executed.

  if-else-if construct(mutiway decision statement)

      The expression shall be evaluated in order.If any expression is true,the statement associated with it shall be executed,and this shall terminate the whole chain.

  Each statement is either a single statement or a block of statement.

2.case statement(multiway decision statement)

   The case expression given in parentheses shall be evaluated exactly once and before any of the case item expression.

   The case item expressions shall be evaluated and compared in the exactly order in which they are given.

   If there is a default case item, it is ignored during this linear search.

   During the linear search , if one of the case item shall be executed, and the linear search shall terminate.

   If all comparisions fail and the default item is given,then the default item statement shall be executed .

  If the default statement is not given and all of the comparision fail, then none of the case item statements shall be executed.

    linear search ??

  The case statement differs from the multiway if-else-if construct in two important ways:

   a) The condition expression in the if-else-if construct are more general than comparing one expression with several others,as in the case statement.

  b)  The case statement provides a definitive result when there are x and z values in an expression.

         In a case expression comparison,the comparison only succeeds when each bit mathes exactly with respect to the valule 0 、 1、x and z.

         As a consequence, care is needed in  specifying the expression in the case statement.

         The bit length of all the expression shall be equal so that exact bitwise matching can be performed.

         The length of all the case item expressions as well as the case expression in the parentheses,shall be made equal to the length of the longest case expression and case item expression.

         If any of these expression is unsigned , then all of them shall be treated as unsigned.

         If all of these expressions are signed, then they shall be treated as signed.

3.casex / casez --dont care

   case x --- treats x /z as do-not-care condition

   case z ---treats z as do-not-care condition

   allows the use of mark(?) in place of z it these case statements(可以用来实现具有优先级的分支选择类似if-else-if)

   eg:

        reg [7:0] ir;

        casez(ir)

           8'b1???????:instruction(ir);

           8'b01??????:instruction(ir);

           8'b001?????:instruction(ir);

           8'b0001????:instruction(ir);

           8'b00001???:instruction(ir);

      endcase

      constant expression in case statement(也可以实现priority,觉得相比于 mark(?)实现priority,这个更好 )

       reg [2:0] encode;

       case(1)

          encode[2]: $display("Select line 2");

          encode[1]:$display("Select line 1");

          encode[0]:$display("Select line 0");

          default $display("Error:one of the bits expected ON");

         endcase

verilog behavioral modeling--branch statement的更多相关文章

  1. verilog behavioral modeling --loop statement

    1.forever 2.repeat 3.while 4.for The for statement accomplishes the same results as the following ps ...

  2. verilog behavioral modeling ---Block statements

    block statements : 1. sequential block  : begin-end block 2.parallel block       :  fork - join bloc ...

  3. verilog behavioral modeling --procedural assignments

    1.procedural assignments are used for updating reg ,integer , time ,real,realtime and memory data ty ...

  4. verilog behavioral modeling--overview

    1.verilog behavioral models contain procedural statements that control the simulation and manipulate ...

  5. verilog behaviral modeling -- procedural timing contronls

    1.delay control : an expression specifies the time duration between initially encountering the state ...

  6. verilog behavioral modeling--procedural continous assignment(不用)

    assign / deassgin force /release the procedural continuous assignments(using keywords assign and for ...

  7. verilog behavioral modeling--blocking and nonblocking

                                                                                                 BLOCKIN ...

  8. verilog behavioral modeling--sequential and parallel statements

    1.Sequential statement groups the begin-end keywords: .group several statements togethor .cause the ...

  9. verilog FAQ(zz)

    1. What is the race condition in verilog? Ans :The situation when two expressions are allowed to exe ...

随机推荐

  1. PostgreSQL-6-数据分组

    基本语法 SELECT column-list FROM table_name WHERE [ conditions ] GROUP BY column1, column2 HAVING [ cond ...

  2. java多线程模拟红绿灯案例

    代码Lighter.java: package pack1; /** * 灯线程 * @author Administrator * */ public class Lighter extends T ...

  3. [題解]hdu_6412公共子序列

    https://blog.csdn.net/nka_kun/article/details/81902421 #include<bits/stdc++.h> #define ll long ...

  4. SimpleDateFormat 如何安全的使用?

     前言 为什么会写这篇文章?因为这些天在看<阿里巴巴开发手册详尽版>,没看过的可以关注微信公众号:zhisheng,回复关键字:阿里巴巴开发手册详尽版 就可以获得. 关注我 转载请务必注明 ...

  5. jQuery属性和样式操作

    回顾 1. jquery基本使用 <script src="jquery.min.js"></script><script> $(functio ...

  6. CF1025B Weakened Common Divisor

    思路: 首先选取任意一对数(a, b),分别将a,b进行因子分解得到两个因子集合然后取并集(无需计算所有可能的因子,只需得到不同的质因子即可),之后再暴力一一枚举该集合中的元素是否满足条件. 时间复杂 ...

  7. SQL Server 2008添加字段成功,但提示列名无效

    在sql后查询,给现有表添加一个字段,即执行sql语句: alter table [sxrq_1108].[dbo].[公司周报表详情] add 总计 int default 0 然后在上述sql查语 ...

  8. 在每天黄金时刻将数据库中数据获取包装成Excel表

    过程: 1.由Timer对象实现安排指定的任务在指定的时间进行重复的固定的延迟操作 a.设定时间间隔24小时:PERIOD_DAY = 24 * 60 * 60 * 100; b.指定每天执行操作的时 ...

  9. 关于搭建系统直播和Thinkphp的杂谈(持续更新)

    Q:Access denied for user 'root'@'localhost' 错误 A:第一种:配置文件中把数据库的用户名密码再改一遍,把runtime里的文件删除  第二种:修改syste ...

  10. (转)RAM、ROM、SRAM、DRAM、SSRAM、SDRAM、FLASH、EEPROM的区别

    RAM(Random Access Memory) 随机存储器.存储单元的内容可按需随意取出或存入,且存取的速度与存储单元的位置无关的存储器.这种存储器在断电时将丢失其存储内容,故主要用于存储短时间使 ...