Pointers and references: Difference between revisions

→‎Double Pointers: Fixed incorrect example - double pointers can only work from zero page memory
(→‎Double Pointers: Fixed incorrect example - double pointers can only work from zero page memory)
Line 18:
 
<lang 6502>LDA #$30
STA $200000
LDA #$50
STA $200101
 
LDA #$80
STA $200505
LDA #$90
STA $200606
 
 
Line 31:
LDY #$07
 
LDA ($200000),y ;the values ofat $200000 and $200101 are looked up and swapped (this is a little-endian cpu after all)
;and the value at (that address plus Y) is loaded. In this example, this equates to LDA $5037
LDA ($200000,x) ;x is added to $200000 and the values at that address and the one after are looked up and swapped, and the
;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}}==
1,489

edits