EXE aborts with uncatched error

Program runs fine in gold editor environment, but aborts after bind as EXE.

Here is the program:

LIBRARY "hexlib.trc"
DECLARE DEF Bin$, CONVERT
LIBRARY "strlib.trc"
DECLARE DEF Mid$, RJust$

OPTION BASE 0

DIM count( 0)

LET power_two = 16
LET bit_len = power_two
LET p_num = 2 ^ power_two
LET q_num = p_num

MAT REDIM count( 0 TO ( p_num - 1))

MAT count = ZER

LET start = time

! Matrix arithemetic in 4VBC for * AND conjunction
!
! a1 a2 a3 a4 a5 a6 a7 a8 * c1 c3 c5 c7 d1 d3 d5 d7 =
! b1 b2 b3 b4 b5 b6 b7 b8 c2 c4 c6 c8 d2 d4 d6 d8
!
! b1c2 b2c4 b3c6 b4c8 b5d2 b6d4 b7d6 b8d8 a1c1 a2c3 a3c5 a4c7 a5d1 a6d3 a7d5 a8d7

FOR p_matrix = ( p_num - 1) TO 0 STEP -1

LET outer_time = Time

LET rjust_bin_num$ = RJust$( Bin$( p_matrix), bit_len, "0")

! b1b2b3b4b5b6b7b8_$ renamed to b1_b8_$
! a1a2a3a4a5a6a7a8_$ renamed to a1_a8_$

LET b1_b8$ = rjust_bin_num$[ 1: 8]
LET a1_a8$ = rjust_bin_num$[ 9:16]

LET b1 = VAL( b1_b8$[ 1:1])
LET b2 = VAL( b1_b8$[ 2:2])
LET b3 = VAL( b1_b8$[ 3:3])
LET b4 = VAL( b1_b8$[ 4:4])
LET b5 = VAL( b1_b8$[ 5:5])
LET b6 = VAL( b1_b8$[ 6:6])
LET b7 = VAL( b1_b8$[ 7:7])
LET b8 = VAL( b1_b8$[ 8:8])

LET a1 = VAL( a1_a8$[ 1:1])
LET a2 = VAL( a1_a8$[ 2:2])
LET a3 = VAL( a1_a8$[ 3:3])
LET a4 = VAL( a1_a8$[ 4:4])
LET a5 = VAL( a1_a8$[ 5:5])
LET a6 = VAL( a1_a8$[ 6:6])
LET a7 = VAL( a1_a8$[ 7:7])
LET a8 = VAL( a1_a8$[ 8:8])

FOR q_matrix = ( q_num - 1) TO 0 STEP -1

LET bin_num$ = Bin$( q_matrix)
LET rjust_bin_num$ = RJust$( bin_num$, bit_len, "0")

! c2c4c6c8d2d4d6d8_$ replaced by c2_d8_$
! c1c3c5c7d1d3d5d7_$ replaced by c1_d7_$

LET c2_d8$ = rjust_bin_num$[ 1: 8]
LET c1_d7$ = rjust_bin_num$[ 9:16]

LET c2 = VAL( c2_d8$[ 1:1])
LET c4 = VAL( c2_d8$[ 2:2])
LET c6 = VAL( c2_d8$[ 3:3])
LET c8 = VAL( c2_d8$[ 4:4])
LET d2 = VAL( c2_d8$[ 5:5])
LET d4 = VAL( c2_d8$[ 6:6])
LET d6 = VAL( c2_d8$[ 7:7])
LET d8 = VAL( c2_d8$[ 8:8])

LET c1 = VAL( c1_d7$[ 1:1])
LET c3 = VAL( c1_d7$[ 2:2])
LET c5 = VAL( c1_d7$[ 3:3])
LET c7 = VAL( c1_d7$[ 4:4])
LET d1 = VAL( c1_d7$[ 5:5])
LET d3 = VAL( c1_d7$[ 6:6])
LET d5 = VAL( c1_d7$[ 7:7])
LET d7 = VAL( c1_d7$[ 8:8])

! b1c2 b2c4 b3c6 b4c8 b5d2 b6d4 b7d6 b8d8 a1c1 a2c3 a3c5 a4c7 a5d1 a6d3 a7d5 a8d7

LET b1c2$ = Bin$( b1 * c2)
LET b2c4$ = Bin$( b2 * c4)
LET b3c6$ = Bin$( b3 * c6)
LET b4c8$ = Bin$( b4 * c8)
LET b5d2$ = Bin$( b5 * d2)
LET b6d4$ = Bin$( b6 * d4)
LET b7d6$ = Bin$( b7 * d6)
LET b8d8$ = Bin$( b8 * d8)

LET a1c1$ = Bin$( a1 * c1)
LET a2c3$ = Bin$( a2 * c3)
LET a3c5$ = Bin$( a3 * c5)
LET a4c7$ = Bin$( a4 * c7)
LET a5d1$ = Bin$( a5 * d1)
LET a6d3$ = Bin$( a6 * d3)
LET a7d5$ = Bin$( a7 * d5)
LET a8d7$ = Bin$( a8 * d7)

LET result$ = b1c2$ & b2c4$ & b3c6$ & b4c8$ & b5d2$ & b6d4$ & b7d6$ & b8d8$ & a1c1$ & a2c3$ & a3c5$ & a4c7$ & a5d1$ & a6d3$ & a7d5$ & a8d7$
LET bin_num = CONVERT( "B" & result$)

LET count( bin_num) = count( bin_num) + 1

NEXT q_matrix

PRINT
PRINT "outer loop"; p_matrix; Time - outer_time

NEXT p_matrix

LET count_tot = 0

OPEN #2: NAME "matrix_output_16.txt", CREATE NEWOLD, ACCESS OUTIN, ORGANIZATION TEXT
ERASE #2

FOR p_matrix = 0 TO p_num - 1

LET test$ = RJust$( Bin$( p_matrix), power_two, "0")

PRINT test$;
PRINT USING " ###,###": count( p_matrix)

LET count_tot = count_tot + count( p_matrix)
PRINT #2: test$;
PRINT #2, USING " ###,###": count( p_matrix)

NEXT p_matrix

PRINT
PRINT "Total ";
PRINT USING " ###,###": count_tot
PRINT #2
PRINT #2: "Total ";
PRINT #2, USING " ###,###": count_tot
PRINT
PRINT "Time "; Time - start
PRINT #2
PRINT #2: "Time "; Time - start

CLOSE #2

STOP

END