Parameter Passing: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 33: | Line 33: | ||
LDX $20 ;load the value at memory address $20 into the X register. |
LDX $20 ;load the value at memory address $20 into the X register. |
||
DEX ;subtract 1 from the value in the X register. This is only a copy. The actual value stored at $20 is unchanged. |
DEX ;subtract 1 from the value in the X register. This is only a copy. The actual value stored at $20 is unchanged. |
||
;Keep in mind that this is true for INX/INY/DEX/DEY but not INC/DEC. |
|||
BIT $2002 ;Set the flags as if the value stored at address $2002 was bitwise ANDed with the accumulator. |
BIT $2002 ;Set the flags as if the value stored at address $2002 was bitwise ANDed with the accumulator. |
||
Line 39: | Line 40: | ||
LDA $40 ;load the value stored at memory address $40 into the accumulator |
LDA $40 ;load the value stored at memory address $40 into the accumulator |
||
ROR A ;rotate right the accumulator. This is only a copy. The actual value stored at $40 is unchanged.</lang> |
ROR A ;rotate right the accumulator. This is only a copy. The actual value stored at $40 is unchanged.</lang> |
||
The main takeaway from this is that by default, the use of <code>LDA/LDX/LDY</code> commands to load from memory is pass-by-value. In order to actually update the memory location, you must store the value back into the source memory address. |
|||
====Functions==== |
====Functions==== |
||
Whether a function's parameters are pass-by-value or pass-by-reference ultimately depends on how it is written and which opcodes are used. |
Whether a function's parameters are pass-by-value or pass-by-reference ultimately depends on how it is written and which opcodes are used. |