| 
 | 
|   | 
  | 
 
  | 
 
 | 
 | 
 
 | 
 
|   | 
  | 
 
  | 
 
|   | 
  | 
Conditional Operators
 | 
  
|   | 
  | 
 
  | 
 
 | 
 | 
-     The conditional operator has the following C-like format:
 
-  cond_expr ? true_expr : false_expr
 
 
-     The true_expr or the false_expr is evaluated and used as a result depending on what cond_expr evaluates to (true or false).
 
 
 | 
 
|   | 
  | 
 
  | 
 
|   | 
  | 
 
  | 
 
 | 
 | 
 
 | 
 
|   | 
  | 
 
  | 
 
|   | 
  | 
Example : Conditional Operators
 | 
  
|   | 
  | 
 
  | 
 
 | 
 | 
  1 program conditional {
  2   bit out;
  3   reg enable,data ;
  4   
  5   enable = 0;
  6   data  = 1; 
  7   out = (enable) ? data : 1'bz;
  8   printf(" Enable %b  Data %b    Out %b\n",enable,data,out);
  9 
 10   enable = 1;
 11   out = (enable) ? data : 1'bz;
 12   printf(" Enable %b  Data %b    Out %b\n",enable,data,out);
 13 }
You could download file conditional.vr here
 | 
 
|   | 
  | 
 
  | 
 
|   | 
  | 
Simulation :  Conditional Operators
 | 
  
|   | 
  | 
 
  | 
 
 | 
 | 
  Enable 0  Data 1    Out z
  Enable 1  Data 1    Out 1
 
 | 
 
|   | 
  | 
 
  | 
 
|   | 
  | 
 
  | 
 
|   | 
  | 
 
  | 
 
 | 
 | 
 
 | 
 
|   | 
  | 
 
  | 
 
 
 
 | 
 | 
| 
  
  | 
  
  | 
  
  | 
| 
 
  
 | 
    | 
 
Copyright © 1998-2025  | 
 
Deepak Kumar Tala - All rights reserved  | 
 
| 
 Do you have any Comment? mail me at:deepak@asic-world.com
  | 
 
 
 
 |