home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / basic / cursor.lha / Cursor / Examples / Link / IsPrime.bas < prev    next >
Encoding:
BASIC Source File  |  1993-10-15  |  1.4 KB  |  40 lines

  1.  
  2. ' This example shows how you can link C-subprograms to BASIC-programs
  3. ' The C-program was compiled using SAS/Lattice C V5.10a
  4.  
  5.  INPUT "Enter a Number";a&
  6.  CALL IsPrime (a&),VARPTR(IsPrime%)
  7.  
  8.  IF IsPrime% THEN
  9.    PRINT a&;" is a prime number"
  10.  ELSE
  11.    PRINT a&;" is no prime number"
  12.  END IF
  13.  
  14.  PRINT
  15.  PRINT "Press any key to continue"
  16.  WHILE INKEY$ = ""
  17.    SLEEP
  18.  WEND
  19.  
  20.  SUB EXTERNAL IsPrime (Number&,IsPrimePointer&) STATIC
  21.  
  22. ' The SUB-command does the following things:
  23. ' - Whenever you call 'IsPrime' via the CALL-command the parameters of the
  24. '   CALL-command are converted to the types specified in the SUB-command
  25. '   and dumped on the stack.
  26. ' - The C or assembly program is called. It must have the name '_ISPRIME'
  27. '   (must be in upper case). You MUST disable the stack-checking at the
  28. '   beginning of a C-procedure (SAS/Lattice C: "lc -v").
  29. ' - At the moment it is not possible to get the result of the C-function
  30. '   (returned in D0), thus the C-program must get a pointer to a variable
  31. '   to return anything.
  32. '   In this example program the result is returned in 'IsPrime%'.
  33. ' - 'Cursor' will not create an executable program but an object file, which
  34. '   can be linked with the C-routines.
  35. '   The object file created by 'Cursor' must be the first file linked!
  36. '
  37. ' Note that the new program might not be 'pure' any more, this depends
  38. ' on the linked C or assembly language routines.
  39.  
  40.