da[$index]=0
fi
- echo "${da[$index]}"
+ declare -g __comp_value="${da[$index]}"
}
get_param() {
local mode=$3
local relative_base=$4
- loc=$(get_param_loc dap $pos $mode $relative_base)
+ get_param_loc dap $pos $mode $relative_base
+ loc=$__comp_param_loc
get_value dap $loc
}
case $mode in
0)
get_value dapl $pos
+ declare -g __comp_param_loc=$__comp_value
;;
1)
- echo $pos
+ declare -g __comp_param_loc=$pos
;;
2)
- move_by=$(get_value dapl $pos)
- echo $((relative_base+$move_by))
+ get_value dapl $pos
+ move_by=$__comp_value
+ declare -g __comp_param_loc=$((relative_base+$move_by))
;;
*)
echo "Unknown parameter mode: $mode"
if [ $instruction == "02" ]; then
symbol="*"
fi
- val1=$(get_param data $((pos+1)) ${immediate[1]} $relative_base)
- val2=$(get_param data $((pos+2)) ${immediate[2]} $relative_base)
- res_loc=$(get_param_loc data $((pos+3)) ${immediate[3]} $relative_base)
+ get_param data $((pos+1)) ${immediate[1]} $relative_base
+ val1=$__comp_value
+ get_param data $((pos+2)) ${immediate[2]} $relative_base
+ val2=$__comp_value
+ get_param_loc data $((pos+3)) ${immediate[3]} $relative_base
+ res_loc=$__comp_param_loc
data[$res_loc]=$(($val1 $symbol $val2))
;;
03)
echo >&2
echo "$instruction: '$input'" >&2
echo >&2
- res_loc=$(get_param_loc data $((pos+1)) ${immediate[1]} $relative_base)
+ get_param_loc data $((pos+1)) ${immediate[1]} $relative_base
+ res_loc=$__comp_param_loc
data[$res_loc]=$input
param_count=1
;;
04)
# 04 - output
- val=$(get_param data $((pos+1)) ${immediate[1]} $relative_base)
+ get_param data $((pos+1)) ${immediate[1]} $relative_base
+ val=$__comp_value
echo -n $'\r'" "$'\r' >&2
echo $val
param_count=1
;;
05|06)
# 05 - jump-if-true, 06 - jump-if-false
- val=$(get_param data $((pos+1)) ${immediate[1]} $relative_base)
- jumpto=$(get_param data $((pos+2)) ${immediate[2]} $relative_base)
+ get_param data $((pos+1)) ${immediate[1]} $relative_base
+ val=$__comp_value
+ get_param data $((pos+2)) ${immediate[2]} $relative_base
+ jumpto=$__comp_value
param_count=2
if ( [ $val -ne 0 ] && [ "$instruction" == "05" ] ) ||
( [ $val -eq 0 ] && [ "$instruction" == "06" ] ); then
;;
07|08)
# 07 - is less than, 08 - is equal
- val1=$(get_param data $((pos+1)) ${immediate[1]} $relative_base)
- val2=$(get_param data $((pos+2)) ${immediate[2]} $relative_base)
+ get_param data $((pos+1)) ${immediate[1]} $relative_base
+ val1=$__comp_value
+ get_param data $((pos+2)) ${immediate[2]} $relative_base
+ val2=$__comp_value >&90
echo >&2
echo "$instruction: '$val1' '$val2'" >&2
echo >&2
- res_pos=$(get_param_loc data $((pos+3)) ${immediate[3]} $relative_base)
+ get_param_loc data $((pos+3)) ${immediate[3]} $relative_base
+ res_pos=$__comp_param_loc
data[$res_pos]=0
if [ "$instruction" == "07" ]; then
if [ $val1 -lt $val2 ]; then
09)
# adjust relative base
param_count=1
- val=$(get_param data $((pos+1)) ${immediate[1]} $relative_base)
+ get_param data $((pos+1)) ${immediate[1]} $relative_base
+ val=$__comp_value
relative_base=$((relative_base+$val))
;;
99)