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. github 收藏项目的方法

    1,Watching 需要收藏的项目 2,查看收藏的项目

  2. 洛谷1280(dp)

    题目性质:1.当前节点空闲则必须做任务,而不是可选可不选:2.然而前面的如果能覆盖当前节点,就可以不选. 解决方法:倒着扫可以很好地解决这两个问题.dp[i]为时刻i可得的最大空闲时间.如果此刻没有任 ...

  3. YII报错笔记:<pre>PHP Notice &#039;yii\base\ErrorException&#039; with message &#039;Uninitialized string offset: 0&#039; in /my/test/project/iot/vendor/yiisoft/yii2/base/Model.php:778

    YII常见报错笔记 报错返回的代码如下: <pre>PHP Notice 'yii\base\ErrorException' with message 'Uninitialized str ...

  4. SDIO学习

    https://baijiahao.baidu.com/s?id=1561100856106707&wfr=spider&for=pc http://www.eepw.com.cn/a ...

  5. E - Addition and Subtraction Hard AtCoder - 2273 思维观察题

    http://arc066.contest.atcoder.jp/tasks/arc066_c?lang=en 这类题目是我最怕的,没有什么算法,但是却很难想, 这题的题解是这样的,观察到,在+号里面 ...

  6. L. Right Build bfs

    http://codeforces.com/gym/101149/problem/L 给出一个有向图,从0开始,<u, v>表示要学会v,必须掌握u,现在要学会a和b,最小需要经过多少个点 ...

  7. performSelector withObject afterDelay 在子线程上调用不运行

    如题,这是最近在修改一个数据同步模块时发现的问题.整个数据同步的任务是在App启动后放在一个后台执行的线程中的,执行某个单条数据同步任务成功后,会使用 [self performSelector:(n ...

  8. 06.Javascript——入门this的用法(难点)

    this 的指向 this 是 js 中定义的关键字,它自动定义于每一个函数域内,但是它的指向却让人很迷惑.在实际应用中,this 的指向大致可以分为以下四种情况. 1.作为普通函数调用 当函数作为一 ...

  9. sql server 日期 查询技巧

    CONVERT(varchar(100), SendTime, 23) –-sql里的字段SendTime参数 selectdateName(weekday,getDate());--返回当前星期 s ...

  10. Java基础教程(25)--I/O

    一.I/O流   I/O流表示输入源或输出目标.流可以表示许多不同类型的源和目标,例如磁盘文件.设备.其他程序等.   流支持许多不同类型的数据,包括字节.原始数据类型.字符和对象等.有些流只传递数据 ...