Java however, provides only one: pass-by-value....
So we have to resort to C++ to illustrate this concept.
In some language (like in C++), the spefication can be using a very minor symbol...
But the meaning is significantly changed and you will see a dramatic change in the assembler program
NOTE: get a copy, compile it and run it to see the effect !
The variable i in main() does NOT get incremented !
Assume the following agreement: parameter passed in D0 parameter passed by value C++ code: Assembler code: --------- -------------- main() main: { MOVE.L i, D0 // pass value int i; // of var i func(i); // pass value BSR func ------+ // of var i .... | } | | void func( int x ) func: ADD.L #1, D0 <---+ { // Assume value x = x + 1; // is pass } RTS
(My personal experience has been that after I learned assembler programming, I understood the concepts in high level programming languages much better....)
// func(x,y) computes x^2 + y^2 int func(int x, int y) { x = x + 1; y = y + 1; return(x*x + y*y); } main() { int a, b, c; int i, j, k; c = func(a,b); k = func(i,j); }
main: MOVE.L a, D0 // Pass param 1 MOVE.L b, D1 // Pass param 2 BSR func MOVE.L D7, c // c = func(a,b) MOVE.L i, D0 // Pass param 1 MOVE.L j, D1 // Pass param 2 BSR func MOVE.L D7, k // k = func(i,j) .... .... func: ADD.L #1, D0 // x = x + 1 (because D0 contains the value of x) ADD.L #1, D1 // y = y + 1 (because D1 contains the value of y) MULS D0, D0 // x*x MULS D1, D1 // y*y ADD.L D1, D0 // x*x + y*y MOVE.L D0, D7 // Put return value // in the agreed location RTS