This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
using_tcl_for_fame_and_fortune [2020/02/07 15:18] nelson |
using_tcl_for_fame_and_fortune [2020/02/07 15:22] (current) nelson [Using Looping to Exercise All Combinations of 1's and 0's] |
||
|---|---|---|---|
| Line 40: | Line 40: | ||
| } | } | ||
| - | Or, if what you are forcing is itself a 4-bit quantity, it requires a function to be defined first: | + | Or, if what you are forcing is itself a 4-bit quantity, it requires a function to be defined first to do the integer to binary conversion: |
| - | proc dec2bin i { | + | proc dec2bin i { |
| - | #returns a string, e.g. dec2bin 10 => 1010 | + | #returns a string, e.g. dec2bin 12 => 1100 |
| set res {} | set res {} | ||
| while {$i>0} { | while {$i>0} { | ||
| Line 51: | Line 51: | ||
| if {$res == {}} {set res 0} | if {$res == {}} {set res 0} | ||
| return $res | return $res | ||
| - | } | + | } |
| - | + | ||
| - | set i 0 | + | set i 0 |
| - | while {$i < 16} { | + | while {$i < 16} { |
| - | add_force a [dec2bin $i] | + | add_force a [dec2bin $i] |
| - | run 10ns | + | run 10ns |
| - | incr i | + | incr i |
| - | } | + | } |
| And, if you prefer for-loops: | And, if you prefer for-loops: | ||