CALL Statement


To call an assembly (or machine) language subroutine.


CALL numvar[(variables)]


numvar is the starting point in memory of the subroutine being called as an offset into the current segment.

variables are the variables or constants, separated by commas and enclosed in parentheses, that are to be passed to the routine.

The CALL statement is recommended for interfacing assembly language programs with GW-BASIC. Although the USR function may also be used, CALL is compatible with more languages, produces a more readable source code, and can pass multiple arguments.

Invocation of the CALL statement causes the following to occur:


Strings may be altered by user routines, but their length must not be changed. GW-BASIC cannot correctly erase strings if their lengths are modified by external routines.

For more information on the CALL statement and USR function, see Appendix D in the GW-BASIC User's Guide.

Example 1:

100 DEF SEG=&H2000
110 ARK=0
120 CALL ARK(A, B$, C)

Line 100 sets the segment to hex 2000. ARK is set to zero so that the call to ARK executes the subroutine at location 2000:0.

Example 2:

The following sequence of 8086 Assembly Language demonstrates access of the parameters passed and stored in variable C:

MOV BP, SP      ; Gets current stack position in BP.
MOV BX, 8[BP]   ; Gets address of B$ descriptor.
MOV CL, [BX]    ; Gets length of B$ in CL.
MOV DX, 1[BX]   ; Gets address of B$ text in DX.
MOV SI, 10[BP] ; Gets address of A in SI.
MOV DI, 6[BP]   ; Gets pointer to C in DI.
MOVSW           ; Stores variable A in C.
RET 6           ; Restores stack and returns.

MOVSW copies only two bytes. This is sufficient if variables A and C are integer. Four bytes must be copied if they are single precision; eight bytes, if they are double precision.

Example 3:

100 DEF SEG=&H2000
110 ACC=&H7FA
120 CALL ACC(A, B$, C)

Line 100 sets the segment to hex 2000. The value of variable ACC is added into the address as the low word after the DEF SEG value is shifted four bits to the left (this is a function of the microprocessor, not of GW-BASIC). Here, ACC is set to &H7FA, so that the call to ACC executes the subroutine at the location hex 2000:7FA (absolute address hex 207FA).