Example of Passing Numerics from Basic to MASM by Value (49395)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • 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
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q49395

SUMMARY

The two programs below demonstrate how a Microsoft Basic program passes standard numeric types to assembly language by value.

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 BNUMVAL.BAS, which passes two standard numeric types to assembly language by value:
   DECLARE SUB ValInt(BYVAL i%)
   DECLARE SUB ValLong(BYVAL l&)
   i% = ASC("A")
   l& = ASC("B") * 65536 + ASC("C")
   CLS
   CALL ValInt(i%)
   CALL ValLong(l&)
   END
				
The following program is ANUMVAL.ASM, which gets two standard numeric types by value and prints them out:
; The following handy .MODEL MEDIUM,Basic directive is found in MASM
; 5.10 but not in earlier versions:
.MODEL MEDIUM, Basic
.CODE
        PUBLIC ValInt, ValLong
ValInt  PROC
        push bp
        mov bp, sp            ; set stack frame
        mov dx, [bp+6]        ; get integer
        mov ah, 02            ; DOS interrupt to print character
        int 21h
        pop bp
        ret 2
ValInt  ENDP

ValLong PROC
        push bp
        mov bp, sp            ; set stack frame
        mov dx, [bp+6]        ; get first part of long
        mov ah, 02            ; DOS interrupt to print character
        int 21h
        mov dx, [bp+8]        ; get second part of long
        int 21h               ; print it
        pop bp
        ret 4
ValLong ENDP
        END
				
To demonstrate these programs from an .EXE program, compile and link as follows:

BC BNUMVAL.BAS;
MASM ANUMVAL.ASM;
LINK BNUMVAL ANUMVAL;

BNUMVAL.EXE produces the following output:

ABC


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