home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / basic / bascmnot.lbr / BASCOM1.NQT / BASCOM1.NOT
Encoding:
Text File  |  1986-07-14  |  4.1 KB  |  96 lines

  1.           Notes on the Use of BASCOM #1
  2.  
  3.             STRING SEGMENTING
  4.  
  5.         (C) Copyright 1985 Merlin R. Null
  6.              (818) 762-1429
  7.  
  8. BASCOM  does optimization  of  string  storage  in  the  compiled
  9. program by matching strings of more  than  four  bytes.   Only  a
  10. single copy of the matched  string  is  stored  in  the  compiled 
  11. program  (unless the /S switch is used with the  compiler).   You
  12. can cause this feature of the compiler to shorten your program by
  13. deliberately breaking strings into matching segments.
  14.  
  15. For example:
  16.  
  17. 100 PRINT"File not found - please try again"
  18. .
  19. .
  20. 200 PRINT"Bad file name - please try again"
  21.  
  22. Both of these strings would be stored in  full  in  the  compiled
  23. program, even though parts of them match.  To allow BASCOM to see
  24. the match and shorten up the string space, change them to:
  25.  
  26. 100 PRINT"File not found";" - please try again"
  27. .
  28. .
  29. 200 PRINT"Bad file name";" - please try again"
  30.  
  31. The break in the string with  ";"  allows BASCOM to treat them as
  32. two distinct strings.   To verify that you did it correctly, dump
  33. the COM file in PATCH, EDFILE or DDT and look at the string space
  34. in the ASCII portion of the dump.   You  should see only one copy
  35. of  " - please try again"  or whatever the strings were you tried
  36. to match.   The strings must be absolutely identical, down to the
  37. last space, to be matched.   In the above example,  4 bytes would
  38. be saved in the compiled program.   If  there  were  3  of  these
  39. strings to be matched, the savings would be 17 bytes.  4 strings,
  40. would save 30 bytes.
  41.  
  42. The main drawback to this is that it will  be  more  difficult  to
  43. read and patch  the  compiled  program  directly.   In  the  above
  44. example, if you were to patch the string  " - please try again" to
  45. " - arrgh, forget it",   all  places  in  the  program  that  used
  46. " - please try again" would change.   This  might be exactly  what
  47. you want, if you are not releasing the source to your program  and
  48. want to make it more difficult to modify.
  49.  
  50. The minimum string length which will result in saving bytes in the
  51. compiled program depends on the number  of strings  matched.   The
  52. following chart gives the number of bytes saved for various string
  53. lengths and number of matching strings:
  54.  
  55.  
  56.           BYTES SAVED WHEN STRINGS ARE MATCHED
  57.  
  58. Number of |        Number of bytes in a single string
  59. Identical |
  60. Strings   | 7   8   9  10  11  12  13  14  15  16  17  18  19  20
  61. =================================================================
  62.     2     | -   -   -   -   -   -   -   -   0   1   2   3   4   5
  63.     3     | -   -   -   -   1   3   5   7   9  11  13  15  17  19
  64.     4     | -   -   0   3   6   9  12  15  18  21  24  27  30  33
  65.     5     | -   -   3   7  11  15  19  23  27  31  35  39  43  47
  66.     6     | -   1   6  11  16  21  26  31  36  41  46  51  56  61
  67.     7     | -   3   9  15  21  27  33  39  45  51  57  63  69  75
  68.     8     | -   5  12  19  26  33  40  47  54  61  68  75  82  89
  69.     9     | -   7  15  23  31  39  47  55  63  71  79  87  95 103
  70.    10     | 0   9  18  27  36  45  54  63  72  81  90  99 108 117
  71.  
  72.  
  73. Points on the chart marked  "-"  indicate  an increase in program
  74. size.   This  chart  was  prepared  by  compiling  short programs
  75. containing only strings to print to the screen.   For the  actual
  76. saving in bytes, compare the bytes used or bytes free reported by
  77. L80 at the end of linking.  The number of bytes free  reported by
  78. BASCOM does not show the savings.   BASCOM  will  report the file
  79. with the divided strings as longer.  The source file IS longer.
  80.  
  81. The number of bytes saved is not hugh,  but it might be just what
  82. is need to shrink a program down to the next lower block size.
  83.  
  84. Of course,  an even easier way to shrink a program is to edit the
  85. strings.   Does  your  program  have  a  paragraph  or  a page of
  86. explanation where a line  or  two  might  do  the  job?   Useless
  87. verbiage on a screen can lead to it not being  read  at  all.   A
  88. help file might have a lot of text, but the main program  prompts
  89. should be short and to the point.
  90.  
  91.                         6-24-85
  92.   63  72  81  90  99 108 117
  93.  
  94.  
  95. Points on the chart marked  "-"  indicate  an increase in program
  96. size.   This  chart  w