--- title: "Tasort" id: 77528 type: "computer_media" slug: "tasort" url: "http://localhost/computer_media/tasort/" markdown_url: "http://localhost/computer_media/tasort.md" published_at: "2026-11-15T18:38:07+00:00" modified_at: "2026-11-15T18:38:07+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/11/tasort-1.png" excerpt: "A machine-code binary-insertion sort for Tasword text files, sorting the lines on any column." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "LKDOS" slug: "lkdos" taxonomy: "post_tag" url: "http://localhost/tag/lkdos/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Utility" slug: "utility" taxonomy: "genre" url: "http://localhost/type/utility/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Tasort%20%281991%29%28-%29%28TS2068%29%28Program%29.zip" tsrun_member: "Tasort (1991)(-)(TS2068)(Program)/Tasort (1991)(-)(TS2068)(Program).tap" mediadate: "1991" images: - url: "http://localhost/wp-content/uploads/2026/11/tasort-1.png" article_media: - id: 23555 title: "Letter about Sorting" type: "article" url: "http://localhost/article/letter-about-sorting/" related_content: - id: 77527 title: "TASORT (Tasword Sort)" type: "computer_media" url: "http://localhost/computer_media/tasort-tasword-sort/" media_type_tags: "Utility" license: false --- # Tasort A binary-insertion sort for Tasword text files: it sorts the 64-character lines of the file in memory (33280 up) by the characters from a chosen column on. The BASIC loader POKEs 147 bytes of machine code, given in hex DATA, to 32999-33145 (the first byte is the sort column, 1 by default) and prints how to use it: LOAD the Tasword file, then RANDOMIZE USR 33000; POKE 32999 with another column (1 to 64) to sort on it. From an unsigned letter on sorting databases; the writer timed it at 6.57 seconds on a 248-line file of random digits. The letter also gives an indexed binary insertion sort in BASIC (in the source code). Lines 9800 and 9900 save to a Larken disk and are not needed from tape; the six lines printed after line 9900 start a second version of the loader whose rest is missing, and are left out of the download. Published in Sinc-Link July-August 1991 ([Letter about Sorting](https://timexsinclair.com/article/letter-about-sorting/)). ## Source Code ``` Indexed Binary sort (BASIC) 1 REM Indexed Binary sort 2 REM Variables: 3 REM a$(n)=array to sort 4 REM i(n) = index 5 REM n = number of records 6 REM hi = top of search 7 REM lo = bottom of search 8 REM pt = middle of search 10 LET i(1)=1 11 FOR i=2 TO n 12 LET t$=a$(i) 13 LET hi=i 14 LET lo=0 15 LET pt=int ((hi+lo)/2) 16 IF pt=lo THEN GO TO 25 17 IF a$(i(pt))>t$ THEN GO TO 20 18 LET lo=pt 19 GO TO 15 20 LET hi=pt 21 GO TO 15 25 FOR j=i TO hi+1 STEP -1 26 LET i(j)=i(j-1) 27 NEXT j 28 LET i(hi)=i 29 NEXT i Sort for Tasword only, using binary insertion routine 2 CLEAR 32998 3 LET sort=33000 10 LET a=10: LET b=11: LET c=12: LET d=13: LET e=14: LET f=15 11 LET x=sort-1 12 READ a$: IF a$="END" THEN GO TO 15 13 FOR i=1 TO LEN a$ STEP 3: POKE x,16*VAL a$(i)+VAL a$(i+1): LET x=x+1: NEXT i 14 GO TO 12 15 PRINT "To use, LOAD file, then:" 16 PRINT '"RANDOMIZE USR ";sort 20 PRINT AT 5,0;"Sort on a different column","(1 <= col <= 64) by:" 21 PRINT '"POKE ";sort-1;",(col)" 999 STOP 1000 DATA "01": REM Default column 1001 DATA "21 00 CD 3E 20 2B BE 28" 1002 DATA "FC 01 40 00 09 7D E6 C0" 1003 DATA "6F E5 21 00 82 01 40 00" 1004 DATA "09 D1 ED 52 D0 19 D5 11" 1005 DATA "C0 81 ED 53 7A 81 E5 E5" 1006 DATA "ED B0 E1 22 7C 81 2A 7C" 1007 DATA "81 ED 5B 7A 81 A7 ED 52" 1008 DATA "CB 1C CB 1D 7D E6 C0 6F" 1009 DATA "B4 28 0D 19 E5 CD 5E 81" 1010 DATA "E1 38 E0 22 7A 81 18 DE" 1011 DATA "E1 ED 5B 7C 81 A7 E5 2B" 1012 DATA "ED 52 38 16 44 4D 19 03" 1013 DATA "11 40 00 EB 19 EB ED B8" 1014 DATA "23 11 C0 81 01 40 00 EB" 1015 DATA "ED B0 E1 18 A0 00" 1019 REM Compare subroutine 1020 DATA "3A E7 80 3D 47 3E 40 11" 1021 DATA "C0 81 28 06 90 C8 23 13" 1022 DATA "10 FC 47 1A BE C0 23 13" 1023 DATA "10 F9 C9 00" 1030 DATA "END" 9800 RANDOMIZE USR 100: SAVE "Tasort.CI"CODE 32999,146 9810 STOP 9900 RANDOMIZE USR 100: SAVE "Tasort.BI" LINE 1 ```