beautypg.com

Opening & closing the driver – Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual

Page 115

background image

8K. Other Languages

II. SOFTWARE GUIDES - 8. Driver488/DRV

II-100

Personal488 User’s Manual, Rev. 3.0

If the argument is a data object, then the subprogram can modify that data object because it has that
object’s memory address. If an expression is passed using call-by-reference, the expression is
evaluated and stored in a temporary location. The address of this temporary is then passed to the
subprogram. The subprogram usually can change this value but it has no effect on the variables of the
calling program.

Call-by-reference can be used to give the same effect as call-by-value. To do this, the arguments are
first copied into temporary locations, then the addresses of these temporaries are passed using call-by-
reference. The calling protocol is call-by-reference because the addresses of the data objects are
passed to the subprogram. However, because these addresses are the addresses of copies of the
arguments and not the actual arguments, the subprogram cannot know the actual addresses of the
arguments, nor can it change their values. This type of call-by-reference is always used for
expressions. When expressions are passed using call-by-reference, they are first evaluated and their
results stored in temporary locations. Then the addresses of these temporaries are passed to the
subprogram.

By forcing the data object to be treated as an expression, call-by-reference can be used with the same
effect as call-by-value as described above. In BASIC, this is accomplished by surrounding the variable
in parentheses:

CALL SUB(A)

calls

SUB

and passes the address of

A

, while:

CALL SUB((A))

calls

SUB

and passes the address of a temporary variable that contains the same value as

A

.

Differences

It is important to note the difference between call-by-value and call-by-reference. In call-by-value, the
subprogram does not know the actual addresses of the arguments and cannot change their values, while
in call-by-reference, the subprogram knows the addresses of its arguments and can change them. This
can have important ramifications. For example, in True Basic, functions are always call-by-value. The
arguments are copied and the addresses of these copies are passed to functions. In contrast, subroutines
are call-by-reference and are passed the addresses of the actual arguments. Thus, if one tries to write a
function that returns the address of a string variable, it does not work! The address returned is the
address of the copy of the string, not the desired address of the actual string variable. Instead, a
subroutine with two parameters must be used, the first being the string whose address is desired, and
the second being set to that address when the subroutine is called.

Opening & Closing the Driver

Any program using Driver488/DRV must first establish communications with the Driver488/DRV
software driver. This is accomplished using the MS-DOS

OPEN

function. In assembly language, this

might appear as follows:

name

DB”

IEEE”,0

;Driver488/DRV device name

ieee

DW0

;Place to hold Driver488/DRV file handle

mov

AH, 3Dh

;Open function

mov

AL, 02

;Access code = read/write

mov

DX,offset
name

;DS:DX - name

int

21h

;Execute DOS function

jc

error

;Error if carry set

mov

ieee, AX

;Save file handle

Once the file is opened, we can communicate with it to perform almost all the functions of
Driver488/DRV. When the program is done, it should close the Driver488/DRV file:

mov

AH,3Eh

;Close function

mov

BX,ieee

;File handle

int

21h

;Execute DOS function

jc

error

;Check for error

or

DL,20h

:Set “don’t check for control characters” bit