You are here: Home DOCUMENTATION information SBASIC Manual - Page 56

Technological Arts Inc.

Your Shopping Cart

Your Cart is currently empty.

SBASIC Manual - Page 56

Article Index
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
Page 11
Page 12
Page 13
Page 14
Page 15
Page 16
Page 17
Page 18
Page 19
Page 20
Page 21
Page 22
Page 23
Page 24
Page 25
Page 26
Page 27
Page 28
Page 29
Page 30
Page 31
Page 32
Page 33
Page 34
Page 35
Page 36
Page 37
Page 38
Page 39
Page 40
Page 41
Page 42
Page 43
Page 44
Page 45
Page 46
Page 47
Page 48
Page 49
Page 50
Page 51
Page 52
Page 53
Page 54
Page 55
Page 56
Page 57
Page 58
Page 59
Page 60
Table of Contents
All Pages

     SBasic User's Manual     SBasic Version 2.7             Page 56
     Printed:  December 5, 1999
     You can also use ASMFUNC to create statements.  Remember that an
     SBasic statement doesn't return a value, but simply performs an
     operation.  For example:

         asmfunc  setstk                ' define an asm entry point

         main:                          ' enter here
         setstk  $0060                  ' change hardware stack addr
         do  loop                       ' silly loop

         asm                            ' switch to assembly language
         setstk                         ' entry point to setstk
             tsx                        ' get current stack addr
             ldx   0,x                  ' get return addr for SB in x
             jsr   _pull                ' get new stack addr in d
             xgdx                       ' new stack in x
             txs                        ' move new stack addr to s
             xgdx                       ' put return addr back in x
             jmp   0,x                  ' return through x
         endasm                         ' back to SBasic


     This example is more advanced and shows how to change the return stack
     pointer from inside SBasic.  The SB program uses the SETSTK statement
     to set the return stack pointer to $60, essentially moving the
     hardware stack.  The tricky part here is that SB will execute this
     statement via a JSR to SETSTK.  If the assembly language code simply
     moved the new stack pointer into the S-register and returned, the
     program would crash since the return address would be undefined.  The
     code above changes the S-register, but saves the return address in the
     X-register.  It finally returns by jumping through the X-register.

     Here you can see how SBasic processes the arguments to a statement.
     The argument $0060 for the SETSTK statement is pushed onto SB's data
     stack; it is NOT passed in the D-register.  Thus, before the assembly
     language code in the SETSTK routine can do anything with the argument,
     it must first execute a JSR to the SB internal routine _PULL.  _PULL
     pulls the top element from SB's data stack and returns it in the D-
     register.  Refer to the GOSUB statement above for details on how
     SBasic parses arguments to statements.

     Note that you don't have to use a JSR to _PULL just to get an argument
     into the D-register.  Advanced programmers can directly access
     arguments using offsets to the Y-register.  Regardless of how you
     access the arguments, however, your assembly language routine MUST
     remove all arguments from the data stack before returning!  If not,
     repeated invocations of your routine will eventually crash the target

     This brings up another element of the ASMFUNC usage.  SBasic does no
     error checking to make sure your program uses an ASMFUNC label
     consistently.  Thus, you could use the same assembly language routine