Converting GWBASIC Programs

ASIC includes a utility (BAS2ASI) that will help you convert your GWBASIC programs to ASIC format. BAS2ASI can often perform much of the conversion necessary and will notify you with warnings and error messages where further attention is required.

Converting In The Integrated Environment

Converting GWBASIC programs to ASIC format is easy in the integrated environment. From the File Menu, select the Convert Option. A file dialog box will be displayed. Select the file to be converted from the list, or type in the file name and press <enter>.

BAS2ASI will convert the file to a file with the same name, but with a ".ASI" file extension. Note, if a file with the same name and an ".ASI" extension already exists, it will be overwritten.

Note: The file must have been saved in ASCII format (i.e., SAVE "filename.BAS",A).

BAS2ASI has several options to allow you to control how much information is written to the convert file (Comments, Warnings, Errors). These are described in Chapter 3.

After the file is converted, ASIC will load the file into the ASIC edit buffer. (Note: a sample GWBASIC program AREA.BAS is included on your ASIC disk).

Converting From the Command Line

You can also run BAS2ASI from the command line. The syntax for this is:
BAS2ASI filename.BAS [option] [option] [option]
option=  NOCOMMENTS     don't write original source to output as REMs
         NOWARNINGS     suppress warnings in output file
         NOERRORS       suppress error messages in output file
          BAS2ASI TEST.BAS


BAS2ASI expects filename.BAS to be a GWBASIC program that has been stored in ASCII format. It will convert this program to ASIC format and store it in a file with the same file name but with an extension of '.ASI'. Based on the file you specify, BAS2ASI will use the following files:
        filename.BAS    <--input GWBASIC file name
        filename.ASI    <--output ASIC file name
        filename.LBL    <--temporary file created/deleted by BAS2ASI
        filename.TMP    <--temporary file created/deleted by BAS2ASI


By default, BAS2ASI includes both the original sources lines as comments, and the converted statements in the ".ASI" file. The NOCOMMENTS will suppress these comments, but will not suppress the conversion of REM statements in the source program. For example,
     Original .BAS file       Converted .ASI File (.ASI with NOCOMMENTS)
     ---------------------    ------------------- -----------------
     20 X=Y*Z                 REM 20 X=Y*Z        X@ = Y@ * Z@
                              X@ = Y@ * Z@


BAS2ASI will generate error messages whenever it cannot convert a statement. Once you become familiar with how BAS2ASI works, you may know which statements won't convert and thus not need these messages. This option let's you suppress the generation of these messages. It will be up to you to determine if ASIC didn't convert some statements.


BAS2ASI will generate warning messages whenever it converts a statement partially. Usually these are generated when the converted statement works slightly differently than the original GWBASIC statement. Once you become familiar with how BAS2ASI works, you may know which statements won't convert fully and thus not need these messages. This option let's you suppress the generation of these messages. It will be up to you to determine if ASIC didn't fully convert some statements.

Conversion Tips

Although BAS2ASI makes a valiant attempt to convert your code as optimally as it can, it will never be as efficient as a good human programmer manually converting a program. This section describes things you can do both before and after converting a program to optimize performance.

Pre-conversion Tips

  1. The default data type in GWBASIC is single precision floating point. BAS2ASI will convert this to an ASIC Decimal data type (which is the least efficient ASIC data type). If you know that the variable will only contain an integer value in the range of +/-32767, change the data type in the BAS file to integer. If you know that all numeric values will fit in this range, add a DEFINT A-Z statement at the start of the BAS file. BAS2ASI will then store these variables in ASIC integer variables which are much more efficient.

  2. String constants longer than 80 characters will be truncated to 80 characters by BAS2ASI. You may wish to consider splitting long constants to 80 character lengths before converting the program.

  3. BAS2ASI has problems converting IF statements with multiple statements embedded. For example (IF A=B THEN PRINT A:PRINT B ELSE PRINT C:PRINT D) BAS2ASI will flag these as syntax errors even though they are legal in GWBASIC. You will have to convert this form of the IF statement manually. This form is legal (IF A=B THEN PRINT A ELSE PRINT B).

  4. DEFINT/DEFSNG/DEFDBL/DEFSTR can be used in GWBasic to redefine a variable on the fly. BAS2ASI will accept this, but you could experience problems, since the DEFXXX is interpreted at conversion time once by BAS2ASI, but is re-interpreted on the fly by GWBASIC. Move all of your DEFXXX's to the top of the program to be safe.

Post-conversion tips

After you convert your program, you may see a number of warnings and errors in the program which require your attention.

Error Messages

If a statement is not supported in ASIC, BAS2ASI will display a statement such as "*** 'xxxx' statement is not supported" (where 'xxxx' is the name of a GWBASIC statement). This indicates a statement or function for which there is not direct equivalent in ASIC. You will have to write your own code in ASIC to accomplish equivalent functionality.

Warning Messages

Sometimes, BAS2ASI will write warnings to your source file. These are prefixed with a "*" character. Usually, this happens when ASIC supports the GWBASIC statement, but not one of the parameters on the statement. These are also written when the ASIC function operates differently.

Syntax Errors

These occur when BAS2ASI finds a statement that it believes is not in the correct GWBASIC format. Correct the statement to the proper GWBASIC syntax and try converting again.

Statement Optimization

If, after you address the above messages, you may find that the converted program performance is not as fast as you would like, you can probably still optimize the converted code further. A major area for improvement can be obtained by changing the data type of ASIC temp variables. Consider the following sample converted file:
       REM 1  DEFINT A-Z
       REM 10 X=Y*Z*Q
       ASIC0@ = Y * Z
       X = ASIC0@ * Q
BAS2ASI generates temporary work variables when simplifying complex GWBASIC expressions to ASIC format. These temporary variables are always defined as decimal data types. However, in the above example, it is clear from the DEFINT statement, that all variables are integers and that we don't need the extra precision of the decimal data type. We could improve performance slightly by changing ASIC0@ to ASIC0. This is especially true if this calculation were performed many times inside a FOR/NEXT loop.


This section describes BAS2ASI conversion limits. In addition to the Warnings and Errors described above, the following limits are in effect.

  1. Any "." characters in variable names are converted to "_". For example," MY.NAME" is translated to "MY_NAME". This is because ASIC does not support "." characters in a variable name.

  2. Single and double precision numbers are converted to the ASIC decimal
         data type.  Thus,
              APPLE   converts to APPLE@
              ORANGE! converts to ORANGE@
              PEAR#   converts to PEAR@
              GRAPE%  converts to GRAPE
  3. WHILE/WEND and IF/THEN/ELSE statements can be nested 25 levels deep.

  4. NEXT statements must include the counter variable name (i.e., "NEXT I", not "NEXT").

  5. Statements that BAS2ASI cannot convert fully will be prefixed with "*". This will cause a syntax error if you compile in ASIC. After you correct the statement, remove the leading "*".

  6. CLOSE Statements in ASIC may only contain integer constants. Other valid GWBASIC constructs are flagged as errors.

  7. String constants on DATA statements must always be enclosed in quotes.

  8. INPUT# file numbers should be in the range 1-3. ASIC will not handleother file numbers. BAS2ASI
    converts each variable on an INPUT# statement into separate INPUT# statements.

  9. LOCATE statements without a ROW or COL specified are flagged as syntax errors.

  10. The filenum parameter of OPEN, INPUT#, PRINT# and close must be a constant, or a syntax error will be generated.

  11. Arrays are limited to 3 dimensions. Up to 25 arrays per program can be used. Arrays must be DIM'd before use.

  12. If/Then/Else statements can be nested up to 25 levels deep