3 filename="${1:-p2_208.txt}"
10 local value=${line#* = }
15 if [ $key == "mask" ]; then
18 # it's a memory instruction, yay
24 base_mask=$(get_base_mask $cur_mask $loc)
27 for mask in "${masks[@]}"; do
28 loc=$(get_value $mask $loc)
39 # here we literally translate the string to contain X if
40 # it's an X, and then check against the value and if either
41 # value or mask has a 1 in that position set it to 1 other
43 for (( a=0; a<36; a++ )); do
44 if [ ${mask:$a:1} == "X" ]; then
46 elif [ ${mask:$a:1} -eq 1 ] || [ $((value & 2**(35-$a))) -gt 0 ]; then
58 local test="${string/X/b}"
63 if [ "$string" == "$test" ]; then
68 # do the 2 potential replacements and run them through
78 local mask_part1=${mask//X/0}
79 local mask_part2=${mask//1/X}
80 mask_part2=${mask_part2//0/1}
81 mask_part2=${mask_part2//X/0}
82 value=$((value | 2#$mask_part1))
83 value=$(( ~ $value & (2**36)-1 ))
84 value=$((value | 2#$mask_part2))
85 value=$(( ~ $value & (2**36)-1 ))
90 while read -u 3 line; do
95 for key in ${!mem[@]}; do
96 total=$((total+${mem[$key]}))