home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / cpm / alphatronic / BASCOM.ZIP / BASCOM.HLP < prev    next >
Text File  |  2000-08-07  |  15KB  |  379 lines

  1. Introduction
  2. Format notation
  3. A sample session
  4. Writing a Basic program to be compiled
  5. Compiler-interpreter differences
  6. New programming features
  7. Second menu: Compiling, linking & loading, errors
  8. :INTRODUCTION
  9.  
  10. The  Microsoft  BASIC Compiler is a highly efficient programming tool  that 
  11. converts  BASIC  programs from BASIC source code into  machine  code.  This 
  12. provides  much  faster  BASIC program execution than  has  previously  been 
  13. possible.  It can make programs run an average of 3 to 10 times faster than 
  14. programs  run under BASIC-80.    Compiled  programs can  be  up to 30 times 
  15. faster  than interpreted programs if maximum use  of integer  variables  is 
  16. made.
  17. :FORMAT NOTATION
  18.  
  19. Wherever  the  format for a statement or command is given  throughout  this 
  20. HELP file, the following rules apply:
  21.  
  22.     1.   Items in capital letters must be input as shown.
  23.  
  24.     2.   Items in lower case letters enclosed in angle brackets ( < >  ) 
  25.          are to be supplied by the user.
  26.  
  27.     3.   Items in sqare brackets ( [ ] ) are optional.
  28.  
  29.     4.   All  punctuation  except  angle brackets  and  square  brackets 
  30.          (i.e.,  commas,  parentheses,  semicolons,  hyphens,  and equal 
  31.          signs) must be included where shown.
  32.  
  33.     5.   Items  followed  by  an ellipsis ( ...  ) may be  repeated  any 
  34.          number of times (up to the length of the line).
  35.  
  36.     6.   Items separated by a vertical bar ( \ ) are mutually exclusive; 
  37.          choose one.
  38. :SAMPLE SESSION 
  39.  
  40. The  following instructions will take you step by step through the compila-
  41. tion process, from typing in the program to running the compiled version of 
  42. it.  
  43.  
  44. STEP 1: PRELIMINARIES
  45.  
  46. Load BASIC-80 (NOT included in the BASCOM package) from disk.  The  program 
  47. will sign on and the letters
  48.  
  49. ok
  50.  
  51. will appear on the screen. Now enter:
  52.  
  53.           AUTO 100, 100
  54.  
  55. This  command  instructs BASIC-80 to automatically generate  line  numbers, 
  56. beginning with line 100 and incrementing by 100 each time you press ENTER.
  57.  
  58. STEP 2: ENTER THE PROGRAM
  59.  
  60. You are now ready to begin typing in your BASIC program.  Anything that you 
  61. know  runs  in BASIC-80 will do.  Alternatively,  just read in  a  BASIC-80 
  62. program you already use.
  63.  
  64. STEP 3: SAVE THE PROGRAM
  65.  
  66. In order for the compiler to process it,  you must save your source program 
  67. in ASCII format. To do so, enter: 
  68.  
  69.           SAVE "MYPROG",A
  70.  
  71. There  is  now a BASIC program called MYPROG.BAS on your diskette  that  is 
  72. ready  to  be compiled.  (A program that is not yet compiled is called  the 
  73. source file.)
  74.  
  75. Return to CP/M by typing SYSTEM.
  76.  
  77. STEP 4: CHECK FOR ERRORS
  78.  
  79. At  this point,  it is a good idea to check the program for syntax  errors. 
  80. Removing syntax errors now will reduce the possibility of having to  recom-
  81. pile later.  To do this, enter:
  82.  
  83.           BASCOM =MYPROG
  84.  
  85. This  command loads the BASIC Compiler and compiles the source file without 
  86. producing an object or listing file.  If you have made any syntax errors, a 
  87. two-letter code will appear on the screen.  If this happens, return to STEP 
  88. 1, use the BASIC-80 interpreter again, and correct the errors.
  89.  
  90. If no errors were encountered, you are ready to continue.
  91.  
  92. STEP 5: COMPILE SOURCE FILE
  93.  
  94. These  commands instruct the BASIC Compiler to compile MYPROG.BAS,  to  put 
  95. the  object in a file named MYPROG.REL,  and to put the listing in  a  file 
  96. named  MYPROG.LST.  (.REL  and .LST are default extensions supplied by  the 
  97. BASIC Compiler.)
  98.  
  99. There  are  now a relocatable object file called MYPROG.REL and  a  listing 
  100. file called MYPROG.LST on the disk.  The object file contains the  machine-
  101. readable  code  generated by the compiler.  The listing file  contains  the 
  102. BASIC  program statements along with the machine language generated by each 
  103. statement. 
  104.  
  105. STEP 6: LOAD AND EXECUTE THE PROGRAM
  106.  
  107. The LINK-80 linking loader is used to produce an executable program. To use 
  108. it, enter:
  109.  
  110.           L80 MYPROG,MYPROG/N/E
  111.  
  112. This command runs LINK-80,  which in turn loads the object file  MYPROG.REL 
  113. into  the correct memory locations,  then writes it to disk as a .COM file. 
  114. During this process (which can take some time),  runtime routines are drawn 
  115. from the BASLIB.REL runtime library.
  116.  
  117. The  compiled program which you stored on your own diskette can be  run  at 
  118. any time,  all by itself,  without using any part of the BASIC Compiler. It 
  119. works just like a standard CP/M command file.  To execute, just enter:
  120.  
  121.           MYPROG
  122.  
  123. The program should then work just as it did in the interpreter .. only much 
  124. faster.
  125. :WRITING A BASIC PROGRAM TO BE COMPILED 
  126.  
  127. BASIC programs which are to be compiled are, for most part, written in just 
  128. the  same  way  you have always written them to run with  the  interpreter. 
  129. However,  there  are some differences between the statements  and  commands 
  130. implemented  in BASIC-80 and those implemented in the BASIC  Compiler  that 
  131. must be taken into consideration.
  132.  
  133. The  Compiler  interacts with the console only to read  compiler  commands. 
  134. These specify what files are to be compiled.  There is no "direct mode", as 
  135. with the MBASIC interpreter. Commands that are usually issued in the direct 
  136. mode with MBASIC are not implemented on the compiler.  The following state-
  137. ments and commands are not implemented and will generate an error message.
  138.  
  139.      AUTO      CLEAR*    CLOAD     CSAVE     CONT
  140.      DELETE    EDIT      LIST      LLIST     RENUM
  141.      SAVE      LOAD      MERGE     NEW       COMMON*
  142.      SYSTEM
  143. *
  144. (Note: Newer releases of the compiler which include the BRUN runtime module 
  145. do support CHAINing with COMMON and CLEAR with certain restrictions.)
  146.  
  147. :FEATURES USED DIFFERENTLY BY THE BASIC COMPILER
  148.  
  149. DEFINT/SNG/DBL/STR
  150. The compiler does not "execute" DEFxxx statements;  it reacts to the static 
  151. occurrence  of these statements,  regardless of the order in which  program 
  152. lines are executed. A DEFxxx statement takes effect as soon as its  line is 
  153. encountered.  Once the type has been defined for a given letter, it remains 
  154. in  effect until the end of the program or until a different DEfxxx  state
  155. ment with that letter takes effect.
  156.  
  157. USRn Functions
  158. USRn  functions are significantly different from the interpreter  versions. 
  159. The  argument  to  the USRn function is ignored and an  integer  result  is 
  160. returned  in  the HL registers.  It is recommended that USRn  functions  be 
  161. replaced  by  the CALL statement.  (See New BASIC Programming Features  for 
  162. definition of CALL.)
  163.  
  164. DIM and ERASE
  165. The DIM statement is similar to the DEFxxx statement in that it is  scanned 
  166. rather than executed.  That is,  DIM takes effect when its  line is encoun-
  167. tered.  If  the default dimension (10) has already been established for  an 
  168. array variable and that variable is later encountered in a DIM statement, a 
  169. DD (redimensioned array) error results.  There is no ERASE statement in the 
  170. compiler,  so arrays cannot be erased and redimensioned. An ERASE statement 
  171. will produce a fatal error.
  172.  
  173. Also  note  that  the values of the subscripts in a DIM statement  must  be 
  174. integer constants;  they may not be variables,  arithmetic expressions,  of 
  175. floating point values. For example,
  176.  
  177.      DIM A1(I)
  178.      DIM A1(3+4)
  179.  
  180. are both illegal statements.
  181.  
  182. END
  183. During execution of a compiled program,  an END statement closes files  and 
  184. returns control to the operating system. The compiler assumes an END at the 
  185. end  of the program,  so it is not necessary to insert an END statement  in 
  186. order to get proper program termination.
  187.  
  188. FOR/NEXT
  189. All FOR/NEXT loops must be statically nested with only 1 NEXT statement for 
  190. each FOR statement.
  191.  
  192. ON ERROR GOTO/RESUME <line number>
  193. If  a  program contains ON ERROR GOTO and RESUME <line number>  statements, 
  194. the  /E compilation switch must be used.  If the RESUME  NEXT,  RESUME,  or 
  195. RESUME  0  form is used,  the /X switch must also be  included.  
  196.  
  197. REM
  198. REM statements or remarks starting with a single quotation mark do not make 
  199. up time or space during execution, and so may be used as freely as desired.
  200.  
  201. STOP
  202. The STOP statement is identical to the END statement. Open files are closed 
  203. and control returns to the operating system.
  204.  
  205. TRON/TROFF
  206. In order to use TRON/TROFF,  the /D compilation switch must be used. Other-
  207. wise,  TRON and TROFF are ignored and a warning message is  generated.  
  208. :NEW BASIC PROGRAMMING FEATURES
  209.  
  210. The  BASIC  Compiler  also  adds  new features  that  will  add  power  and 
  211. efficiency  to  your programming.  Keep in mind when  utilizing  these  new 
  212. features  that while they will compile with no problems,  you cannot run  a 
  213. program  using  these  features with  your  interpreter,   since   BASIC-80
  214. doesn't recognize them.
  215.  
  216. CALL Statement
  217. The  CALL  Statement  allows you to call and transfer flow to  an  assembly 
  218. language or FORTRAN subroutine.
  219.  
  220. The format of the CALL Statement is:
  221.  
  222.      CALL <variable name> [(<argument list>)]
  223.  
  224. where <variable name> and <ergument list> are supplied by you.
  225.  
  226. <variable name> is the name of the subroutine you wish to call.  This  name 
  227. must  be  1  to 6 characters long and must be recognized by  LINK-80  as  a 
  228. global  symbol.  (<variable  name> must be the name of the subroutine in  a 
  229. FORTRAN  SUBROUTINE  statement or a PUBLIC symbol in an  assembly  language 
  230. routine.)
  231.  
  232. <argument  list> is optional and contains the arguments that are passed  to 
  233. the assembly language or FORTRAN subroutine.
  234.  
  235. Example:       120 CALL MYROUT (I,J,K)
  236.  
  237. CHAIN (or RUN)
  238. The CHAIN and RUN statements both perform the same function: they allow you 
  239. to load a file from diskette into memory and run it.  CHAIN (or RUN) closes 
  240. all  open files and deletes the current contents of memory  before  loading 
  241. the  designated program.  The format of the CHAIN (or RUN) statement is  as 
  242. follows:
  243.  
  244.                       CHAIN <filename>
  245.                              OR
  246.                       RUN <filename>
  247.  
  248. where  <filename> is the name used when the file was saved.  (With CP/M the 
  249. default extension .BAS is supplied.)
  250.  
  251. WHILE...WEND
  252. The  WHILE...WEND  statement  is a conditional statement  that  executes  a 
  253. series of statements in a loop as long as a given condition is true.
  254.  
  255. The format of WHILE...WEND is:
  256.  
  257.      WHILE <expression>
  258.           -
  259.           -
  260.      <loop statements>
  261.           -
  262.           -
  263.      WEND
  264.  
  265. where <expression> and <loop statements> are supplied by you.
  266.  
  267. As  long  as <expression> is true (i.e.,  not zero),  loop  statements  are 
  268. executed until the WEND statement is encountered. BASIC then returns to the 
  269. WHILE statement and checks "expression".  If it is still true,  the process 
  270. is  repeated.  If  it is not true,  execution resumes  with  the  statement 
  271. following the WEND statement.
  272.  
  273. WHILE/WEND loops may be nested to any level, as long as they are statically 
  274. nested.  Each  WEND  will match the most recent WHILE.  An unmatched  WHILE 
  275. statement causes a "WHILE without WEND" error, and an unmatched WEND state-
  276. ment causes a "WEND without WHILE" error.
  277.  
  278. Example:
  279.           090  'BUBBLE SORT ARRAY A$
  280.           100  FLIPS=1 'FORCE ONE PASS THRU LOOP
  281.           110  WHILE FLIPS
  282.           115       FLIPS=0
  283.           120       FOR I=1 TO J=1
  284.           130            IF A$(I)>A$(I+1) THEN
  285.                          SWAP A$(I),A$(I+1):FLIPS=1
  286.           140       NEXT I
  287.           150  WEND
  288.  
  289. Double Precision Transendental Functions
  290. SIN,  COS,  TAN,  SQR,  LOG, and EXP now return double precision results if 
  291. given  double  precision arguments.  Exponentiation with  double  precision 
  292. operands will return double precision results.
  293.  
  294. Long Variable Names
  295. Variable  names  may  be up to 40 characters long with  all  40  characters 
  296. significant.  Letters,  numbers,  and the decimal characters are allowed in 
  297. variable names,  but the name must begin with a letter.  Variable names may 
  298. also  include  all  BASIC-80  commands,  statements,  function  names,  and 
  299. operator names.
  300.  
  301. Expression Evaluation in the  BASIC Compiler
  302. During program compilation,  when the BASIC Compiler evaluates expressions, 
  303. the operands of each operator are converted to the same type,  that of  the 
  304. most precise operand. For example,
  305.  
  306.           QR=J%+A!+Q
  307.  
  308. causes J% to be converted to single precision and added to A!.  This result 
  309. is coverted to single precision and added to Q.
  310.  
  311. The  Compiler  is  more limited than the interpreter  in  handling  numeric 
  312. overflow. For example, when run on the interpreter the following program
  313.  
  314.           I%=20000
  315.           J%=20000
  316.           K%=-30000
  317.           M%=I%+J%-K%
  318.  
  319. yields 10000 for M%.  That is,  it adds I% to J% and, because the number is 
  320. too large,  it converts the result into a floating point number. K% is then 
  321. converted  to floating point nd subtracted.  The result of 10000 is  found, 
  322. and is converted back to integer and saved as M%.
  323.  
  324. The Compiler,  however, must make type conversion decisions during compila-
  325. tion. It cannot defer until the actual values are known. Thus, the compiler 
  326. would generate code to perform the entire operation in integer mode. If the 
  327. /D switch were set,  the error would be detected.  otherwise,  an incorrect 
  328. answer would be produced.
  329.  
  330. In  order  to  produce  optimum efficiency in  the  compiled  program,  the 
  331. compiler  may perform any number of valid algebraic transformations  before 
  332. generating the code. For axample, the program
  333.  
  334.           I%=20000
  335.           J%=-18000
  336.           K%=20000
  337.           M%=I%+J%+K%
  338.  
  339. could produce an incorrect result when run.  If the compiler actually  per-
  340. forms the arithmetic in the order shown,  no overflow occurs.  However,  if 
  341. the compiler performs I%+K% first and then adds J%, an overflow will occur.
  342.  
  343. The  Compiler  follows  the rules of operator  precedence  and  parenthetic 
  344. modification of such precedence, but no other guarantee of evaluation order 
  345. can be made.
  346.  
  347. Using Integer Variables To Optimize Speed
  348. In order to produce the fastest and most compact object code possible, make 
  349. use of integer variables. For example, this program
  350.  
  351.           FOR I=1 TO 10
  352.           A(I)=0
  353.           NEXT I
  354.  
  355. can  execute approximately 30 times faster by simply substituting "I%"  for 
  356. "I".  It  is  especially advantageous to use integer variables  to  compute 
  357. array  subscripts.  The  generated  code is significantly faster  and  more 
  358. compact.
  359.  
  360. Maximum Line Length
  361. The Compiler cannot accept a physical line that is more than 253 characters 
  362. in length. A logical statement, however, may contain as many physical lines 
  363. as  desired.  Use line feed to start a new physical line within  a  logical 
  364. statement.
  365. ::BASCOM2.HQP
  366. 
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  a random file.
  378. 51        Internal error
  379.       An  internal    malfunc