I am currently learning about stack, stackframes and call by value/call by reference in assembly. The one thing, I dont understand is, what are the advantages of passing a value by reference, because how i understand it, the adresses of the values are also pushed on stack between two stackframes, similar two call by value, where a copy of the value gets pushed on the stack. Am I missing something or can someone pls explain the differnece to me with an short example? Thanks! (btw sry for the bad english)
Asked
Active
Viewed 438 times
1
-
1Advantages of pass by reference: 1) possibly less memory usage and faster due to avoiding a copy 2) callee can modify the argument – Jester Sep 16 '17 at 14:09
-
If you know C, compare `void foo(int a)` vs. `void foo(int *pa)`. Obviously `const int *pa` is not faster, but it can be with a large struct. – Peter Cordes Sep 16 '17 at 14:22
-
so for instance a subroutine can change the values in the stackframe of the main, when i use call by reference? – Hungryapeman Sep 16 '17 at 14:41
-
At the assembly level, the two methods are the same: the CPU only deals with pure values, `0x1000` could be the address of an object (pass-by-reference) or the value of the said object (pass-by-value). A subroutine almost never touch another one's variables directly but it can change an object in memory if it knows where it is (read pointers, a way to implement pass-by-reference) – Margaret Bloom Sep 16 '17 at 15:12