Example Passing Numerics from Basic to MASM by Far Reference (49385)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q49385

SUMMARY

The two programs below demonstrate how a Microsoft Basic program can pass standard numeric types to assembly language routines.

MORE INFORMATION

For more information about passing other types of parameters between Basic and MASM, search in the Microsoft Knowledge Base using the following word:

BAS2MASM

Code Example

The following Basic program is BNUMFAR.BAS, which passes standard numeric types to assembly language routines:
   DECLARE SUB Numint(SEG i%)
   DECLARE SUB Numlong(SEG l&)
   DECLARE SUB Numsng(SEG s!)
   DECLARE SUB Numdbl(SEG d#)
   i% = 2
   l& = 4
   s! = 3.4
   d# = 5.6
   CLS

   PRINT "         BEFORE","AFTER"
   PRINT "Integer: ";i%,,
   CALL Numint(i%)
   PRINT i%

   PRINT "Long   : ";HEX$(l&),,
   CALL Numlong(l&)
   PRINT HEX$(l&)

   PRINT "Single : ";s!,
   CALL Numsng(s!)
   PRINT s!

   PRINT USING "Double : ##.####            ";d#,
   CALL Numdbl(d#)
   PRINT USING "##.####"; d#

   END
				
The following program is ANUMFAR.ASM, which accepts standard numerics by far reference and alters their values:
; The following handy .MODEL MEDIUM,Basic directive is found in MASM
; 5.10 but not in earlier versions:
.MODEL MEDIUM, Basic
.CODE
        PUBLIC Numint, Numlong, Numsng, Numdbl
Numint  PROC
        push bp
        mov bp, sp        ; set stack frame
        push es
        mov es, [bp+8]    ; get seg
        mov bx, [bp+6]    ; get offset
        mov ax, es:[bx]   ; get actual integer
        shl ax, 1         ; multiply by 2
        mov es:[bx], ax   ; put back new value
        pop es
        pop bp
        ret 4
Numint  ENDP

Numlong PROC
        push bp
        mov bp, sp        ; set stack frame
        push es
        mov es, [bp+8]    ; get seg
        mov bx, [bp+6]    ; get offset
        mov cx, es:[bx]   ; get actual long
        mov ax, es:[bx+2] ; switch high and low words
        mov es:[bx+2], cx ; put back new value
        mov es:[bx], ax
        pop es
        pop bp
        ret 4
Numlong ENDP

Numsng  PROC
        push bp
        mov bp, sp        ; set stack frame
        push es
        mov es, [bp+8]    ; get seg
        mov bx, [bp+6]    ; get offset
        mov ax, es:[bx+2] ; get actual single
        or ah, 80h        ; set sign bit
        mov es:[bx+2], ax ; put back new value
        pop es
        pop bp
        ret 4
Numsng  ENDP

Numdbl  PROC
        push bp
        mov bp, sp         ; set stack frame
        push es
        mov es, [bp+8]     ; get seg
        mov bx, [bp+6]     ; get offset
        mov ax, es:[bx+6]  ; get actual double
        or ah, 80h         ; set sign bit
        mov es:[bx+6], ax  ; put back new value
        pop es
        pop bp
        ret 4
Numdbl  ENDP

        END
				
To demonstrate these programs from an .EXE program, compile and link as follows:

BC /O BNUMFAR.BAS;
MASM ANUMFAR.ASM;
LINK BNUMFAR ANUMFAR;

BNUMFAR.EXE produces the following output:
            BEFORE     AFTER
   Integer:  2          4
   Long   :  4          40000
   Single :  3.4       -3.4
   Double :  5.6000    -5.6000
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB49385