Jump to content

Parameter Passing: Difference between revisions

m
Line 33:
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.
;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.
Line 39 ⟶ 40:
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>
 
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====
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.
1,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.