Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| intro_example:alu [2025/04/21 23:34] – [Using enumerations] rajit | intro_example:alu [2025/04/21 23:49] (current) – rajit | ||
|---|---|---|---|
| Line 35: | Line 35: | ||
| [] c = 2 -> O!(a&b) | [] c = 2 -> O!(a&b) | ||
| [] c = 3 -> O!(a|b) | [] c = 3 -> O!(a|b) | ||
| + | ] ] | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====== 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? | ||
| + | { | ||
| + | int a, b; | ||
| + | | ||
| + | |||
| + | 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) | ||
| ] ] | ] ] | ||
| } | } | ||