Parameter Passing: Difference between revisions

m
Line 89:
Parameters are typically passed via the stack or through registers. For human-written assembly, the programmer can pass an argument by reference by passing a pointer to the argument rather than the argument itself. Of course, the function will need to dereference that pointer; however whether the function writes back the new value to that memory address is also decided by the programmer. This means that just because a parameter is passed by reference does not mean that it gets altered by the function that received it. This (contrived) example shows this concept in action.
 
<langsyntaxhighlight lang="68000devpac">start:
start:
MOVE.L #$00FF0000,D0 ;load D0 with the pointer 0x00FF0000 (I decided this was a pointer just for example's sake.)
MOVE.L D0,-(SP) ;push that value onto the stack.
Line 102 ⟶ 103:
MOVE.L (A0),D1 ;dereference the pointer (we're treating it as a pointer to an int)
ADD.L D1,D0 ;add the values.
RTS ;and return</lang>
</syntaxhighlight>
 
 
===Example [[Ada]]===
404

edits