Intel 9800758-02 manual Calling Subroutines

Page 88

Calling Non-BASIC-80 Subroutines

BASIC-80

When you have determined the optimum starting address for your subroutine, you can LOCATE it there with this command. LOCATE converts the relocatable object code to absolute object code, according to the starting address given. An example of giving the starting address for your subroutine code is shown below.

LOCATE :F1 :PLMSUB.OBJ TO :F1 :PLMSUB.LD CODE (OEECOH)

This example converts the relocatable object code in :Fl :PLMSUB.OBJ to absolute object code in the output file :Fl :PLMSUB.LD, and makes all addresses in the subroutine relative to OEECOH. Refer to the ISIS-II User's Guide for further details of using LOCATE.

After LOCATE has converted your relocatable code to absolute object code, you can load it into memory with the ISIS-II Monitor DEBUG command. When you enter DEBUG followed by the filename of the load module, the subroutine is loaded into memory at the address specified in the load module. The starting address displays on your terminal. You then enter GS, which returns you to ISIS-II with the subroutine loaded at the specified address. From here.you can invoke BASIC-SO and call the subroutine.

NOTE

You must give the MEMTOP option to reserve memory each time BASIC-SO is invoked.

Calling Subroutines

After a subroutine is loaded into memory, you can call it from BASIC-80. First, invoke BASIC-SO as you normally do, and give the MEMTOP option as previously specified.

The first step in calling a subroutine is defining its address with the DEFUSR func- tion. Up to 25 subroutines can be addressed in this way, with an integer in the range

0-24. The starting address of the subroutine is given in hexadecimal:

DEFUSR5=OEECOH

Once BASIC-SO knows where USR5 is located, you can call it. When you call it, you must supply any needed variables. Since the protocol for passing parameters follows PL/M conventions, you can only directly pass 2-byte integer variables or 2-byte addresses. If you specify a floating-point variable or a string variable you must use the VARPTR function to pass the address of the desired variable. For example, to pass the addresses of two floating-point numbers (Kl and K2):

120 A = USR5 (VARPTR(K1), (VARPTR(K2»

BASIC-SO goes to the address where Kl is stored (VARPTR(Kl) and the address where K2 is stored (VARPTR(K2». Once it has found these two values, it passes them to the subroutine.

If BASIC-SO encounters new variables after executing line 120 above, the memory locations of Kl and K2 can change, causing errors. Be sure that all variables are defined before using the VARPTR instruction.

In the example shown, once the parameters are passed, the subroutine executes. Because of PL/M-80calling conventions BASIC-80 expects the returned result to be a two-byte integer in the HL register-pair, and assigns this 16-bit value to A.

E-2

Image 88
Contents BASIC-SO Reference Manual A108/0979/7500 FL Preface Page Contents Illustrations Chapter Introduction to BASIC-80 Invoking BASIC-80Examples Introduction to BASIC-80Basic filename MEMTOPaddress FilenameListing the Directory of a Disk Renaming a FileChanging File Attributes Deleting a FileYou can now run, list, or edit the program Save LP ,ACommands StatementsBASIC-80 Commands Contd BASIC-80 StatementsBASIC-80 Statements Contd BASIC-80 FunctionsBASIC-80 Functions Contd Representing Data FunctionsConstants Integer ConstantsDecimal Integer Constants Hexadecimal Integer ConstantsSingle-Precision Floating-Point Constants Octal Integer ConstantsDouble-Precision Floating-Point Constants String Constants String VariablesThis is a string constant $ = Enter next data stringL4! = Csng l4 YI,1String Arrays Arithmetic Operators BASIC-SO Operators in Order of Precedence ContdLogical Operators String OperatorNumeric Expressions String ExpressionsEntering and Editing Programs 30 A=8*52 30 A=830 A=8*52 30 A=8*37 30 A--=8xx*522537 Control-R a = 8*37Subcommand Command 3D press 3, then D resultsInteger D If AB thenIf AB then 120 Else Null SET Syntax of the X subcommand is At this point, the other editing subcommands may be usedPrint Undefined SET The E subcommand is entered Integer C character characterMove the cursor to PRINT. Enter 2C RE L Print Undefined SET. Enter a LSyntax Error Messages BASIC-80 Error MessagesOverflow, Underflow, and Divide-by-Zero Error Trapping Trace Facility Error Simulation Error HandlingRestarting Program Execution If line 40 is replaced withOpening a Sequential File Open 1,#1,F1DATESRefer to for further details of Print Using Writing to a Sequential FileReading from a Sequential File If executed four times, it would read all eight valuesClosing a Sequential File Value of R$ would beDefining a Random 1/0 Field-FIELD BuffersField #3, 20 AS N$ Disk File Input/Output Field #3, 20 AS N$, 9 AS SS$Opening and Closing a Random Disk File Reading from a Random 1/0 FileAny of the parameters can be variables To read the next recordWriting to a Random 1/0 File IntegerSingle-precision value Double-precision valueMKI$ Attrib Fdrive numberfilename, W1 Attrib Fdrive numberfilename, WOAuto first lineJ, increment Clear expression,addressCommands and Statements CloseDEF FNX Rules for function name are the same as for variable nameDefsng Defdbl Defstr Defint DIM DeleteError DIREdit ENDError expression ExitField FOR-NEXT-STEPGET GosubFor variable=expression to expression Step expression GET I file number ,record numberInput IF-THEN-ELSEGoto Kill LETLine Input ListLSET, Rset LoadMerge NEWNext 9 16On ... Goto On ... GosubOpen OUT Option BasePoke Print Print UsingString Fields Numeric fields If X$=SEVEN and Y$=EIGHT, the results of line 40 would bePrun PUTRandomize ReadREM Resume ReturnSave RUN line numberlstring expression ,FLine number RUN filename 60 ENDTRON, Troff ? 5,8,2Wait WidthABS ATNCint CHR$Functions Csng CVI CVS10 A# = 1.00/3.00 AO/o =Dskf EOFFIX Ok·INP HexsInputs Instr INTLEFT$ LEN LOCLOF LOGMKI$ MKS$ MKD$ MID$OCT$ Rights Peek expressionPOS integer RIGHT$ string,integerSGN SINSpaces 10 a =1SPC SPC integerIf A$ = 2 then Print Correct Else Goto SQRexpressionTAB expression STR$ expressionTAN expression Here is an example of how the USRn statement is used 60 AO/o =Appendix a BASIC-SO Error Codes Table A-I. BASIC-80 Error CodesTable A-I. BASIC-SO Error Codes Contd Appendix B BASIC-SO Reserved Words Page To halt program execution and return to command LevelTo tab across the line To resume program execution after it is stopped byPage Table D-l. Ascii Code List Appendix D Ascii CodesTable D-2. Ascii Code Definition BELAppendixe Calling Subroutines Figure B-1. Internal Representation of Numbers and Strings Some Real Examples RESULT=USR%1VARPTRA, VARPTRB, VARPTRC» PRINTA+B+C= ResultFigure E-2 /8085 Assembly Language Program Figure E-3. PL/M-80 Program Appendix F RMX/SO BASIC-SO Initializing the Predefined RMX/SO BASIC-SO Configuration ISIS-II BASIC-SOTable F-l. Sample Configuration Jumper Wiring OOOOH-OFFFHGenerating Boot-Loaded and PROM-Based Versions BASIC-80 Source FilesBASIC-80 Object Files BASIC-80 Executable FilesGenerating a Boot-Loaded RMX/80 BASIC-80 That are not boot loaded This option is used to allocate memory. It is 1 if the bootSetting baud rates, refer to the RMX/SO Users Guide This option enables your user-written I/O drivers if youISBC 80/20-4 Generating a PROM-Based RMX/80 BASIC-80 Prom F1 RMX820.L1BSTART, & FOBASCM.OBJ,& FORMXBAS.LlB F1 DFSDIR. L1BDIRECTORY ,RENAM E,& F1 MTI810.L1B Configuring DFS on an iSBC 80/10 Adding BASIC-SO to an Existing RMX/SO ConfigurationConfiguration Requirements ISBC SO/10 System ClockPublic Variables Adding User-Written I/O Drivers to RMX/SO BASIC-SO Open 0,#1, L1LlSTFigure F-S. Sample User-Written 1/0 Driver Routine Altering BASIC-80 Workspace Burning a BASIC-80 Program Into PromBaprom F1HEATER.BAS Page Index Ase BASIC-80 RIGHT$,7-1O Request for Readerscomments 111111