About the parameter passing methd in Randall Hyde's AOA book( DOS Version)

Started by qlmi, July 15, 2006, 08:07:06 AM

Previous topic - Next topic

qlmi

I am reading Doctor Hyde's AOA book(Dos version). In chapter 11, there are a lot of   discussion about pass parameter. i want to understand the difference pass by reference and pass by value-returned, but any samples i havn't found. would you please help me?

Dinosaur

You are referring to high level language passing of data to asm routine I assume.
If you are passing by reference you are passing the address of the value, not the value.
If you are passing the value, then this value is immidiatly available in the registers
In the example below, Basic to Asm I passed 2 parameters.
The first by value and the second an addr.

Quote
   PUSH    BP
   MOV     BP,SP
   ;-------------------------------
   MOV   BX,[BP+6]       ;get value from stack.
   MOV   Value,BX

   MOV   BX,[BP+8]       ;get address from stack.
   MOV   ValueAddr,BX    ;Save the address
   MOV   AX,[BX]        ;get value at that address
   MOV   Value,AX       ;and save it.


Hope this helps.

qlmi

I'm confused with the three passing mode: pass by reference, pass by value-returned, pass by value. Could you please give me some hint or comparing example?

tenkey

First, a definition:

Argument list - the information provided by a caller, and used by the called routine to gain access to arguments. The argument information can be put on a stack (Windows convention), placed in registers, or even placed in an arbitrary local or global location.

1) Pass by value:

Data is calculated or copied and made accessible to the called routine. The optimal implementation is to put only the data into the argument list. This way, there is no address information at all, so you cannot store a result in an arbitrary location specified by the caller at the call point.

2) Pass by reference:

The address of the argument object is put into the argument list. The address is used by the routine code to perform all memory accesses to the argument object, both the fetching and storing of data. The result is immediate modification of the original argument object.

3) Pass by value-return:

The address of the argument object is put into the argument list. The argument object is copied to local storage by the routine. The routine uses the local copy for all "argument" accesses. At the end of the routine, the original address information is used to copy the local argument object data into the original argument object. The result is deferred modification of the original argument object.

Note that "value-return" is just a variation of "reference". In a HLL, "value-return" uses one name to refer to two data objects.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8