Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  QuickBASIC's default is a medium memory model, with multiple executable
  code segments and one default data segment. As in interpreted BASIC, you
  must design your subroutines to use a far call-return sequence, but you
  can access the single default data segment with near addresses. Also, like
  interpreted BASIC, compiled QuickBASIC passes parameters by reference in
  the order they appear in the BASIC source code.

  The BASIC source code to call an assembly language subroutine is much
  simpler in QuickBASIC than in interpreted BASIC, as you'll see when you
  examine the sample code on the following page.

  DEFINT A-Z                      ' default all variables to integer type
  DECLARE SUB MEDABS (A%)         ' declare the assembler subroutine

  FOR X = -10 TO 10
   Y = X
   CALL MEDABS(Y)                 ' call the subroutine
   PRINT "ABS("; X; ")=";Y
   NEXT
  END

  The subroutine itself, however, is nearly identical to the version called
  from interpreted BASIC:

  MEDABS_TEXT     SEGMENT byte public 'CODE'
                  ASSUME  cs:MEDABS_TEXT

                  PUBLIC  MEDABS
  MEDABS          PROC    far             ; call with far CALL

                  push    bp
                  mov     bp,sp

                  mov     bx,[bp+6]       ; BX = address of first parameter
                  mov     ax,[bx]

                  cwd
                  xor     ax,dx
                  sub     ax,dx

                  mov     [bx],ax         ; leave result at parameter address

                  pop     bp
                  ret     2               ; far return, discard parameter value

  MEDABS          ENDP

  MEDABS_TEXT     ENDS

  The only differences between this version of MedAbs() and the version used
  with interpreted BASIC are related to the way the subroutine is linked to
  the BASIC program. The compiled-BASIC version does not contain a BLOAD
  header because BLOAD isn't used to link the subroutine. Instead it
  contains a PUBLIC declaration for the name of the subroutine. When you use
  the linker to generate an executable program, the linker associates the
  PUBLIC name with the same name used in the BASIC program.

  --------------------------------------------------------------------------
  NOTE:
    QuickBASIC provides two different ways to link an assembly-language
    subroutine to BASIC programs. One is to use the BC compiler to compile
    your BASIC source code, and then to link the resulting object (OBJ) file
    with the assembled subroutine's object file. The other technique is to
    use LINK and LIB to create a Quick library so that the subroutine can be
    accessed within the QuickBASIC environment. The QuickBASIC manuals
    describe both techniques in detail.
  --------------------------------------------------------------------------

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson