param_count=3
case $instruction in
01|02)
+ # 01 - add, 02 multiply
symbol="+"
if [ $instruction == "02" ]; then
symbol="*"
data[$res_loc]=$(($val1 $symbol $val2))
;;
03)
+ # 03 - read input
read -p "input: " input
res_loc=${data[$((pos+1))]}
data[$res_loc]=$input
param_count=1
;;
04)
+ # 04 - output
if [ ${immediate[1]} -eq 1 ]; then
echo ${data[$((pos+1))]}
else
param_count=1
;;
05|06)
+ # 05 - jump-if-true, 06 - jump-if-false
val=${data[$((pos+1))]}
jumpto=${data[$((pos+2))]}
param_count=2
continue
fi
;;
- 07)
+ 07|08)
+ # 07 - is less than, 08 - is equal
val1=${data[$((pos+1))]}
val2=${data[$((pos+2))]}
res_pos=${data[$((pos+3))]}
if [ ${immediate[2]} -eq 0 ]; then
val2=${data[$val2]}
fi
- if [ $val1 -lt $val2 ]; then
- data[$res_pos]=1
+ data[$res_pos]=0
+ if [ "$instruction" == "07" ]; then
+ if [ $val1 -lt $val2 ]; then
+ data[$res_pos]=1
+ fi
else
- data[$res_pos]=0
- fi
- ;;
- 08)
- val1=${data[$((pos+1))]}
- val2=${data[$((pos+2))]}
- res_pos=${data[$((pos+3))]}
- if [ ${immediate[1]} -eq 0 ]; then
- val1=${data[$val1]}
- fi
- if [ ${immediate[2]} -eq 0 ]; then
- val2=${data[$val2]}
- fi
- if [ $val1 -eq $val2 ]; then
- data[$res_pos]=1
- else
- data[$res_pos]=0
+ if [ $val1 -eq $val2 ]; then
+ data[$res_pos]=1
+ fi
fi
;;
99)