Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Article Q49385
◄Contents► ◄Index► ◄Back►
─────────────────────────────────────────────────────────────────────────────
◄Knowledge Base Contents► ◄Knowledge Base Index►
Example Passing Numerics from Basic to MASM by Far Reference - Q49385
The two programs below demonstrate how a Basic program can
pass standard numeric types to assembly language routines.
The following Basic program is BNUMFAR.BAS, which passes standard
numeric types to assembly language routines:
Code Example
------------
DECLARE SUB Numint(SEG i%)
DECLARE SUB Numlong(SEG lng&)
DECLARE SUB Numsng(SEG s!)
DECLARE SUB Numdbl(SEG d#)
i% = 2
lng& = 4
s! = 3.4
d# = 5.6
CLS
PRINT " BEFORE","AFTER"
PRINT "Integer: ";i%,,
CALL Numint(i%)
PRINT i%
PRINT "Long : ";HEX$(lng&),,
CALL Numlong(lng&)
PRINT HEX$(lng&)
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:
.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