Functions

BASIC-80

Only integers can be used as arguments; other variables must be passed by reference. This is done with the VARPTR function, which returns the address of the specified variable.

USR[$I#l% I!][n] [(parameter... )]

Here is an example of how the USRn statement is used:

10 CLEAR 1000, ODFFFH

20DEFUSR4 = OEOOOH

30A$ = "A STRING"

40A = 1E4

50A# = 14D-3

60AO/o = 12

70B = USR ! 4 (VARPTR(A!),VARPTR(K1),VARPTR(R#),VARPTR(LA%»

Arguments are returned in a similar fashion, unless the type character is omitted, in which case registers Hand L are used.

Appendix E gives details of loading and running ASM-80, PL/M-80,and FORTRAN-80 subroutines that may be called with USRn.

VAL

The VAL function returns the numerical value of string X$. If the string does not represent a valid number, VAL(X$) equals O.

VAL (string expression)

10 INPUT A$

20IF VAL(A$) = 0 THEN 60

30A1 = VAL(A$) * 52

40PRINT A1, A$

50END

60PRINT "ENTER NUMERIC DATA ONLY."

70GOT010

RUN

?4

208 4

VARPTR

The VARPTR function returns the address in memory of a variable or the in- put/ output buffer associated with a file number. If the variable has not yet been assigned a value, an ILLEGAL FUNCTION CALL error results. The main use of VARPTR is to pass variable or array addresses to assembly-language subroutines. Arrays are passed by specifying VARPTR (A (0» (or VARPTR (A(l» if OPTION BASE 1 is in effect) so that the lowest addressed element of the array is returned. All simple variables should be assigned values in a program before calling VARPTR for any array; otherwise, allocation of a new simple variable will cause the addresses of all arrays to change. See Appendix E for further information about using VARPTR.

VARPTR (variablel#file number)

7-14

Page 78
Image 78
Intel 9800758-02 manual Here is an example of how the USRn statement is used, 60 AO/o =