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 Q49392
◄Contents► ◄Index► ◄Back►
─────────────────────────────────────────────────────────────────────────────
◄Knowledge Base Contents► ◄Knowledge Base Index►
Example of Passing User-Defined Type from Basic to MASM (Far) - Q49392
The two programs shown below demonstrate how a Microsoft Basic program
passes a user-defined type to assembly language by far reference.
More Information:
The following Basic program is UFAR.BAS, which passes a user-defined
type to assembly language by far reference.
Code Example
------------
DEFINT A-Z
DECLARE SUB MasmSub (BYVAL segment, BYVAL offset)
TYPE mixed
i AS INTEGER
lng AS LONG
s AS SINGLE
d AS DOUBLE
fx AS STRING * 19
END TYPE
DIM dummy AS mixed
CLS
PRINT "Calling assembly routine to fill the user-defined type."
CALL MasmSub(VARSEG(dummy), VARPTR(dummy))
PRINT "Values in user-defined type:"
PRINT "Integer: ", dummy.i
PRINT "Long: ", dummy.lng
PRINT "Single: ", dummy.s
PRINT "Double: ", dummy.d
PRINT "fixed-length String: ", dummy.fx
END
The following program is UAFAR.ASM, which gets a user-defined type by
far reference and copies data into it:
.MODEL MEDIUM
usrdefType STRUC
iAsm DW 10
lAsm DD 43210
sAsm DD 32.10
dAsm DQ 12345.67
fxAsm DB 'Fixed-length string'
usrdefType ENDS
.DATA
AsmRec usrdefType <>
PUBLIC MasmSub
MasmSub PROC FAR
push bp
mov bp,sp
push es
push di
push si
push cx
mov es,[bp+8] ; Get segment of user-defined type.
mov di,[bp+6] ; Get offset of user-defined type.
mov si,OFFSET AsmRec
mov cx,37 ; Size of structure.
rep movsb ; Copy values to Basic variable.
pop cx
pop si
pop di
pop es
pop bp
ret 4
MasmSub ENDP
END
To demonstrate these programs from an .EXE program, compile and link
as follows:
BC /O UFAR.BAS;
MASM UAFAR.ASM;
LINK UFAR UAFAR;
UFAR.EXE produces the following output:
Integer: 10
Long: 43210
Single: 32.1
Double 12345.67
fixed-length String: Fixed-length string