Parameter Passing: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 121:
 
Trying to modify an argument with ''intent in'' triggers an error at compile time.
 
===Example [[Z80 Assembly]]===
Like with other assembly languages, how parameters are passed is up to the programmer, and the CPU doesn't restrict how it's done. Read-only memory is immutable of course. Typically, parameters are passed in by registers or the stack. Registers are quicker and don't require you to "dance around" the return address of a function call, but the stack is much larger than the Z80's pool of registers ever could be.
 
The key to passing by value or by reference when needed is to know which operations directly affect memory and which do not. The following instructions directly alter memory (this is not an exhaustive list):
 
* <code>EX (SP),HL</code>
* <code>INC (HL), INC (IX+##), INC (IY+##)</code>
* <code>DEC (HL), DEC (IX+##), DEC (IY+##)</code>
* <code>RES #,(HL), RES #,(IX+##), RES #,(IY+##)</code>
* <code>SET #,(HL), SET #,(IX+##), SET #,(IY+##)</code>
* <code>RL(HL), RL(IX+##), RL(IY+##)</code>
* <code>RR(HL), RR(IX+##), RR(IY+##)</code>
* <code>RLC(HL), RLC(IX+##), RLC(IY+##)</code>
* <code>RRC(HL), RRC(IX+##), RRC(IY+##)</code>
* <code>SLA(HL), SLA(IX+##), SLA(IY+##)</code>
* <code>SLL(HL), SLL(IX+##), SLL(IY+##)</code>
* <code>SRL(HL), SRL(IX+##), SRL(IY+##)</code>
* <code>SRA(HL), SRA(IX+##), SRA(IY+##)</code>
* <code>LDI, LDD, LDIR, LDDR</code>
1,489

edits