Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
intro_example:alu [2025/04/21 23:27] – created rajitintro_example:alu [2025/04/21 23:49] (current) rajit
Line 34: Line 34:
           [] c = 1 -> O!(a-b)           [] c = 1 -> O!(a-b)
           [] c = 2 -> O!(a&b)           [] c = 2 -> O!(a&b)
-          [] c = 3 -> O!(a | b)+          [] c = 3 -> O!(a|b)
        ] ]        ] ]
     }     }
 } }
 </code> </code>
-    + 
 +====== Using enumerations ====== 
 + 
 +Rather than hard-coding the control values, a user-defined enumeration can be used to make the ACT  
 +more readable. 
 + 
 +<code act> 
 +defenum alu_ctrl { 
 +   ADD, SUB, AND, OR 
 +};    
 + 
 +defproc alu (chan?(int) A, B; chan?(alu_ctrl) ctrl; chan!(int) O) 
 +
 +   int a, b; 
 +   alu_ctrl c; 
 +    
 +   chp { 
 +      *[ A?a, B?b, ctrl?c; 
 +          [ c = alu_ctrl.ADD -> O!(a+b) 
 +          [] c = alu_ctrl.SUB -> O!(a-b) 
 +          [] c = alu_ctrl.AND -> O!(a&b) 
 +          [] c = alu_ctrl.OR -> O!(a|b) 
 +       ] ] 
 +    } 
 +
 +</code> 
 +