USR (int-exp (,int-exp2))

Calls a machine language subroutine at location int-exp. Both int-exp and int-exp2 are decimal. intexp2 is specified and then the value is passed into the BC register pair. If int-exp2 is not used, the BC register pair will contain 0.

The machine language subroutine may use all registers, but the stack MUST be managed so that the number of PUSHes and POPS are equal - nothing must be left on the stack.

To pass a value back to the BASIC program, the result of the subroutine should be placed in the BC register pair. This will become the value of the function. If it is necessary to pass a number of parameters to the subroutine, we suggest that you set aside an area of memory for this purpose. Before entering the subroutine, you would POKE the information in and, after the subroutine, you would PEEK the information.

Program Example

00100 REM A program that will pass control to a machine
00110 REM code sub-routine at 2000H, then return
00120 REM control to BASIC.
00130 REM Data for sub-routine
00140 DATA 17,214,243,33,12,32,1,16,0,237,176,201,77,73,67,82
00150 DATA 79,66,69,69,32,83,89,83,84,69,77,83
00160 REM Poke sub-routine into location 2000H
00170 FOR I= 8192 TO 8219
00180 READ D
00190 POKE I,D
00200 NEXT I
00210 REM Begin main program
00220 HIRES
00230 PLOT 180,77 TO 180,178 TO 330,178 TO 330,77 TO 180,77
00240 USR(8192) : REM A THE SUB-ROUTINE
00250 PLOT 200,97 TO 200,158 TO 310,158 TO 310,97 TO 200,97
00260 END

Try it