Autorem opisu jest Paweł Bogu¶

Microsoft BASIC Reference

Contents

  • Introduction to the Microsoft BASIC Interpreter
  • Special Characters
  • Variable Type Declaration Chars
  • Commands
  • Edit Mode Subcommands
  • Program Statements (except I/O)
  • PRINT USING Format Field Specifiers
  • String Specifiers
  • Input/Output Statements
  • Operators
  • Arithmetic Functions
  • String Functions
  • I/O and Special Functions
  • Reserved Keywords by Version
  • Interpreter Error Codes

  • Introduction to the Microsoft BASIC Interpreter

    This HELP File is derived from the "Microsoft BASIC Reference Manual", and covers the basics of the language. For more detail and instruction, refer to the manual itself.

    The Microsoft BASIC Interpreter is booted as follows: On the Altair's front panel, set the leftmost 8 switches all up, and the others all down. Left EXAMINE, then put all the switches down. Be sure the BASIC disk is in drive 0, and the drive is ready. Then, depress the RUN switch. BASIC should boot up and ask:

    MEMORY SIZE?
    
    To which you should normally respond with the enter key. If you want, you can enter the actual top of memory (in decimal) if for some reason you want BASIC to only see part of your memory. To the next questions, the following are safe answers. Refer to the manual for details:
    LINEPRINTER? C
    HIGHEST DISK DRIVE NUMBER? 0
    NUMBER OF FILES? 5
    NUMBER OF RANDOM FILES? 3
    
    Altair BASIC will print its OK prompt, letting you know it's ready for your commands.

    Special Characters

    ^C   Interrupts program execution and returns to MBASIC
    ^GRings bell at terminal
    DELDeletes last char typed
    ^ITab (every 8)
    ^OHalts/resumes program output
    ^RRetypes the line currently being typed
    ^SSuspends program execution
    ^QResumes execution after ^S
    ^U,^XDeletes line being typed
    CREnds every line being typed in
    LFBreaks a logical line into physical lines
    ESCEscapes Edit Mode Subcommands
    .Current line for EDIT, RENUM, DELETE, LIST, LLIST commands
    &O,&Prefix for Octal Constant
    &HPrefix for Hex Constant
    :Separates statements typed on the same line
    ?Equivalent to PRINT statement


    Variable Type Declaration Characters

    $   String   0 to 255 chars
    %Integer-32768 to 32767
    !Single Precision7.1 digit floating point
    #Double Precision17.8 digit floating point


    Commands

    Command   Syntax   Function
    AUTOAUTO [line][,inc]Generate line numbers
    CLEARCLEAR [,[exp1][,exp2]]Clear program variables; exp1 sets end of memory and exp2 sets amount of stack space
    CONTCONTContinue program execution
    DELETEDELETE [[start][-[end]]]Delete program lines
    EDITEDIT lineEdit a program line
    FILESFILES [filename]Directory
    LISTLIST [line[-[line]]]List program line(s)
    LLISTLLIST [line[-[line]]]List program line(s) on printer
    LOADLOAD filename[,R]Load program; ,R means RUN
    MERGEMERGE filenameMerge prog on disk with that in mem
    NAMENAME old AS newChange the name of a disk file
    NEWNEWDelete current prog and vars
    NULLNULL expSet num of NULLs after each line
    RENUMRENUM [[new][,[old][,inc]]]Renumber program lines
    RUNRUN [line number]Run a prog (from a particular line)
    RUNfilename[,R]Run a prog on disk
    SAVESAVE filename[,A]Save prog onto disk; ,A saves prog in ASCII
    TROFFTROFFTurn trace off
    TRONTRONTurn trace on
    WIDTHWIDTH [LPRINT] expSet term or printer carriage width; default is 80 (term) and 132 (prin)


    Edit Mode Subcommands

    A   Abort -- restore original line and restart Edit
    nCcChange n characters
    nDDelete n characters
    EEnd edit and save changes; don't type rest of line
    Hstr[ESC]Delete rest of line and insert string
    Istr[ESC]Insert string at current pos
    nKcKill all chars up to the nth occurrance of c
    LPrint the rest of the line and go to the start of the line
    QQuit edit and restore original line
    nScSearch for nth occurrance of c
    Xstr[ESC]Goto the end of the line and insert string
    [DEL]Backspace over chars; in insert mode, delete chars
    [CR]End edit and save changes


    Program Statements (except I/O)

    Statement   Syntax   Function
    CALLCALL variable [(arg list)]Call assembly or FORTRAN routine
    DEFDEF FNx[(arg list)]=expArith or String Function
    DEF USRn=addressDefine adr for nth assembly routine
    DEFINT range(s) of lettersDefine default var type INTeger
    DEFSNG --"----"-- Single
    DEFDBL --"----"-- Double
    DEFSTR --"----"-- String
    DIMDIM list of subscripted varsAllocate arrays
    ENDENDStop prog and close files
    ERASEERASE var [,var ... ]Release space and var names
    ERRORERROR codeGenerate error code/message
    FORFOR var=exp TO exp [STEP exp]FOR loop
    GOSUBGOSUB line numberCall BASIC subroutine
    GOTOGOTO line numberBranch to specified line
    IF/GOTOIF exp GOTO line [ELSE stmt ... ]
    IF exp <> 0 then GOTO
    IF/THENIF exp THEN stmt[:stmt] [ELSE stmt ... ]
    IF exp <> 0 then ... else ...
    LET[LET] var=expAssignment
    MID$MID$(string,n[,m])=string2Replace a portion of string with string2; start at pos n for m chars
    NEXTNEXT var[,var ... ]Ends FOR loop
    ON ERRORON ERROR GOTO lineError trap subroutine
    GOTOGOTO lineJump to program line
    ON/GOSUBON exp GOSUB line[,line]Computed GOSUB
    ON/GOTOON exp GOTO line[,line]Computed GOTO
    OUTOUT port,byteOutput byte to port
    POKEPOKE address,byteMemory put
    RESTORERESTORE [line]Reset DATA pointer
    RESUMERESUME or RESUME 0Return from ON ERROR GOTO
    RESUME NEXTReturn to stmt after error line
    RESUME lineReturn to specified line
    RETURNRETURNReturn from subroutine
    STOPSTOPStop prog and print BREAK msg
    WAITWAIT prot,mask[,select]Pause until input port [XOR select] AND mask <> 0


    PRINT USING Format Field Specifiers

    SpecifierDigitsChars   Definition
    #11Numeric field
    .01Decimal point
    +01Print leading or trailing sign
    -01Trailing sign (- if neg, SP otherwise)
    **22Leading asterisk
    $$12Floating dollar sign; placed in front of leading digit
    **$23Asterisk fill and floating dollar sign
    ,11Use comma every three digits
    ^^^^04Exponential format
    _01Next character is literal


    String Specifiers

    Specifier   Definition
    !Single character
    /SPACES/Character field; width=2+number of spaces
    &Variable length field


    Input/Output Statements

    Statement   Syntax   Function
    CLOSECLOSE [[#]f[,[#]f ... ]]Close disk files; if no arg, close all
    DATADATA constant listList data for READ statement
    FIELDFIELD [#]f,n AS string var [,n AS string var ...]Define fields in random file buffer
    GETGET [#]f[,record number]Read a record from a random disk file
    INPUTINPUT [;] [prompt string;] var [,var ...]
    INPUT [;] [prompt string,] var [,var ...]
    Read data from the terminal; leading semicolon suppresses echo of CR/LF and semicolon after prompt string causes question mark after prompt while comma after prompt suppresses question mark
    KILLKILL filenameDelete a disk file
    LINE INPUTLINE INPUT [;] [prompt string;] string varRead an entire line from terminal; leading semicolon suppresses echo of CR/LF
    LINE INPUT #f,string varRead an entire line from a disk file
    LSETLSET field var=string expStore data in random file buffer left-justified or left-justify a non-disk string in a given field
    OPENOPEN mode,[#] f,filenameOpen a disk file; mode must be one of:
    I = sequential input file
    O = sequential output file
    R = random input/output file
    PRINTPRINT [USING format string;] exp [,exp ...]Print data at the terminal using the format specified
    PRINT #f, [USING format string;] exp [,exp ...]Write data to a disk file
    LPRINT [USING format string;] var [,var ...]Write data to a line printer
    PUTPUT [#] f [,record number]Write data from a random buffer to a data file
    READREAD var [,var ...]Read data from a DATA statement into the specified vars
    RSETRSET field var = string expStore data in a random file buffer right justified or right justify a non-disk string in a given field
    WRITEWRITE [list of exps]Output data to the terminal
    WRITE #f, list of expsOutput data to a sequential file or a random field buffer


    Operators

    Symbol   Function
    =Assignment or equality test
    -Negation or subtraction
    +Addition or string concatenation
    *Multiplication
    /Division (floating point result)
    ^Exponentiation
    \Integer division (integer result)
    MODInteger modulus (integer result)
    NOTOne's complement (integer)
    ANDBitwise AND (integer)
    ORBitwise OR (integer)
    XORBitwise exclusive OR (integer)
    EQVBitwise equivalence (integer)
    IMPBitwise implication (integer)
    =,>,<,Relational tests (TRUE=1, FALSE=0)
    <=,=<,
    >=,=>,
    <>

    The precedence of operators is:

    1. Expressions in parentheses
    2. Exponentiation
    3. Negation (Unary -)
    4. *, /
    5. \
    6. MOD
    7. +, -
    8. Relational Operators
    9. NOT
    10. AND
    11. OR
    12. XOR
    13. IMP
    14. EQV

    Arithmetic Functions

    Function   Action
    ABS(exp)Absolute value of expression
    ATN(exp)Arctangent of expression (in radians)
    CDBL(exp)Convert the expression to a double precision number
    CINT(exp)Convert the expression to an integer
    COS(exp)Cosine of the expression (in radians)
    CSNG(exp)Convert the expression to a single precision number
    EXP(exp)Raises the constant E to the power of the expression
    FIX(exp)Returns truncated integer of expression
    FRE(exp)Gives memory free space not used by MBASIC
    INT(exp)Evaluates the expression for the largest integer
    LOG(exp)Gives the natural log of the expression
    RND[(exp)]Generates a random number
    exp <0 seeds new sequence
    exp =0 returns previous number
    exp >0 or omitted returns new random number
    SGN(exp)1 if exp >0
    0 if exp =0
    -1 if exp <0
    SIN(exp)Sine of the expression (in radians)
    SQR(exp)Square root of expression
    TAN(exp)Tangent of the expression (in radians)


    String Functions

    Function   Action
    ASC(str)Returns ASCII value of first char in string
    CHR$(exp)Returns a 1-char string whose char has ASCII code of exp
    FRE(str)Returns remaining memory free space
    HEX$(exp)Converts a number to a hexadecimal string
    INPUT$(length [,[#]f])Returns a string of length chars read from console or from a disk file; characters are not echoed
    INSTR([exp,]str1,str2)Returns the first position of the first occurrence of str2 in str1 starting at position exp
    LEFT$(str,len)Returns leftmost length chars of the string expression
    LEN(str)Returns the length of a string
    MID$(string,start[,length])Returns chars from the middle of the string starting at the position specified to the end of the string or for length characters
    OCT$(exp)Converts an expression to an Octal string
    RIGHT$(str,len)Returns rightmost length chars of the string expression
    SPACE$(exp)Returns a string of exp spaces
    STR$(exp)Converts a numeric expression to a string
    STRING$(length,str)Returns a string length long containing the first char of the str
    STRING$(length,exp)Converts a numeric expression to a string
    VAL(str)Converts the string representation of a number to its numeric value


    I/O and Special Functions

    Function   Action
    CVI(str)Converts a 2-char string to an integer
    CVS(str)Converts a 4-char string to a single precision number
    CVD(str)Converts an 8-char string to a double precision number
    EOF(f)Returns TRUE (-1) if file is positioned at its end
    ERLError Line Number
    ERRError Code Number
    INP(port)Inputs a byte from an input port
    LOC(f)Returns next record number to read or write (random file) or number of sectors read or written (sequential file)
    LPOS(n)Returns carriage position of line printer (n is dummy)
    MKI$(value)Converts an integer to a 2-char string
    MKS$(value)Converts a single precision values to a 4-char string
    MKD$(value)Converts a double precision value to an 8-char string
    PEEK(exp)Reads a byte from memory location specified by exp
    POS(n)Returns carriage position of terminal (n is dummy)
    SPC(exp)Used in PRINT statements to print spaces
    TAB(exp)Used in PRINT statements to tab to specified position
    USR[n](arg)Calls the user's machine language subroutine with the arg
    VARPTR(var)Returns address of var in memory or zero if var has not been assigned a value
    VARPTR(#f)Returns the address of the disk I/O buffer assigned to file number


    Reserved Keywords by Version

    RESERVED WORDS (all versions)

    CLEAR, DATA, DIM, END, FOR, GOSUB, GOTO, IF, INPUT, LET, LIST, NEW, NEXT,
    PRINT, READ, REM, RETURN, RUN, STOP, TO, TAB, THEN, USR

    RESERVED WORDS (8K, Extended, and Disk versions)

    (all the above words plus)
    AND, CONT, DEF, FN, NOT, NULL, ON, OR, OUT, POKE, SPC, WAIT

    RESERVED WORDS (Extended and Disk versions)

    (all the above words plus)
    AUTO, CONSOLE, DEFDBL, DEFINT, DEFSNG, DEFSTR, DELETE,
    EDIT, ELSE, ERASE, ERL, ERR, IMP, INSTR, LINK, KL, LPRINT, MOD, RENUM,
    RESUUME, SPACE$, STRING$, SWAP, TROFF, TRON, VARPTR, WIDTH, XOR

    RESERVED WORDS (Disk BASIC)

    (all the above words plus)
    CLOSE, DSKI$, DSKO$, FIELD, FILES, GET, KILL, LOAD,
    LSET, MERGE, MOUNT, NAME, OPEN, PUT, RSET, UNLOAD.


    Interpreter Error Codes

    Code   Error
    1NEXT without FOR
    2Syntax error
    3RETURN without GOSUB
    4Out of data
    5Illegal function call
    6Overflow
    7Out of memory
    8Undefined line
    9Subscript out of range
    10Redimensioned array
    11Division by zero
    12Illegal direct
    13Type mismatch
    14Out of string space
    15String too long
    16String formula too complex
    18Undefined user function
    19No RESUME
    20RESUME without error
    21Unprintable error
    22Missing operand
    23Line buffer overflow
    26FOR without NEXT
    29WHILE without WEND
    30WEND without WHILE
     
    Disk Errors
     
    50Field overflow
    51Internal error
    52Bad file number
    53File not found
    54Bad file mode
    55File already open
    57Disk I/O error
    58File already exists
    61Disk full
    62Input past end
    63Bad record number
    64Bad file name
    66Direct statement in file
    67Too many files


    Główny spis tre¶ci  ||  Główna strona MITS Altair