\ arrays.seq \ Listing 1. \ Arrays for Forth \ by M.L.Gassanenko autoeditoff CODE [] ( index array -- value ) pop bx pop di shl di push 0 [bx+di] next c; CODE []! ( value index array -- ) pop bx pop di shl di pop 0 [bx+di] next c; CODE []^ ( index array -- address ) pop bx pop di shl di add bx, di push bx next c; : array, ( x0 x1 ... x[n-1] n -- addr ) ( align ) here >r ?dup if 0 swap 1- do i roll , -1 +loop then r> ; code []len ( 1index array -- 2length ) pop bx pop di shl di mov ax, 2 [bx+di] sub ax, 0 [bx+di] shr ax push ax next c; \ \s Auxiliary tools, rather examples : .ARRAY ( array len -- ) ." [ " 0 ?DO I OVER [] 4 .R SPACE LOOP ." ] " DROP ; : .2ARRAY ( array n_rows -- ) CR 6 SPACES ." [" 0 ?DO ( array ) I OVER [] ( array array[i] ) I PLUCK []LEN ( array array[i] len[i] ) CR 9 SPACES .ARRAY LOOP CR 6 SPACES ." ] " DROP ; \ \s Some examples showlines \ The last, delimiting, subarray is needed for []len \ to calculate the length properly 1 2 3 4 5 5 array, 6 7 8 9 4 array, 10 11 12 3 array, 0 array, 4 array, constant x 0 0 x [] [] . 2 0 x [] [] . 0 2 x [] [] . 1 2 x [] [] . 25 1 2 x [] []! 1 2 x [] [] . 1 2 x [] []^ @ . 0 x []len . 1 x []len . 2 x []len . x 3 .2array off> listvar