3 inst
[$
((count
++))]=$line
5 echo "read $count instructions, starting execution"
8 while [[ ${inst[pc]+set} ]]; do
10 read i r o
<<< "${inst[pc]}"
12 hlf
) case $r in a
) a
=$
((a
/2));; b
) b
=$
((b
/2));; *) exit 2;; esac
14 tpl
) case $r in a
) a
=$
((a
*3));; b
) b
=$
((b
*3));; *) exit 2;; esac
16 inc
) case $r in a
) a
=$
((a
+1));; b
) b
=$
((b
+1));; *) exit 2;; esac
19 jie
) case $r in a
,) ((a
%2));; b
,) ((b
%2));; *) exit 2;; esac
20 pc
=$
((pc
+($? ? o
: 1))) ;;
21 jio
) case $r in a
,) ((a
==1));; b
,) ((b
==1));; *) exit 2;; esac
22 pc
=$
((pc
+($? ?
1 : o
))) ;;
23 *) echo "invalid instruction $i, exiting"; exit 1 ;;
26 echo "final register state a=$a b=$b, after $count instructions executed"