Pointers and references: Difference between revisions
→Double Pointers: Fixed incorrect example - double pointers can only work from zero page memory
Puppydrum64 (talk | contribs) m (→Pointers) |
Puppydrum64 (talk | contribs) (→Double Pointers: Fixed incorrect example - double pointers can only work from zero page memory) |
||
Line 18:
<lang 6502>LDA #$30
STA $
LDA #$50
STA $
LDA #$80
STA $
LDA #$90
STA $
Line 31:
LDY #$07
LDA ($
;and the value at (that address plus Y) is loaded. In this example, this equates to LDA $5037
LDA ($
;value at the resulting address is loaded. In this example, this equates to LDA $9080</lang>
The 65c02 doesn't need to use X or Y when doing the above method. It can do <code>LDA ($00)</code> which has the same effect as <code>LDA ($00),y</code> when Y = 0.
===Indirect Jumps===
Similar to the above, the 6502 can perform an indirect jump. The byte at the specified address is read, and so is the byte at the address after that. Then they are swapped and concatenated into a new address which is then jumped to.
<lang 6502asm>LDA #$40
STA $2000 ;store the low byte into $2000
LDA #$41
STA $2001 ;store the high byte into $2001
JMP ($2000) ;the resulting command jumps to $4140</lang>
The 65c02 has <code>JMP ($####,X)</code> which adds X to the address before the dereference. This can be used as a "computed goto," selecting a piece of code to jump to from a table of memory locations.
The 65816 has <code>JSR ($####,X)</code> which adds X to the address before the dereference. This can be used as a "computed gosub," selecting a function to call from a table of functions.
=={{header|8086 Assembly}}==
|