## News:

11 March 2016 - Forum Rules

## [65816]Store indirect problem

Started by yugisokubodai, January 10, 2018, 10:09:01 PM

#### yugisokubodai

I have this in my loop:

`LDA \$00STA \$1190,x`

This works. Then I modified to

`LDA #\$1190STA \$54...LDA \$00STA (\$54,x)`

Then the result goes wrong. I looked the debugged file and found this:

X=00
STA (\$54,x)[\$80:1190] --> This is OK

X=02
STA (\$54,x)[\$80:2800] --> NG

Can anyone explain where I was wrong?

#### Disch

Indirect,X is not what you want -- and I'd argue is only useful is VERY LIMITED circumstances.  It does the +X BEFORE the pointer is dereferenced, not after.

Example:
When X=2, The pointer being read is from \$56.  It's not reading the pointer from \$54 at all.

What you are looking for is Indirect,Y mode... which is the same, but the indirection happens first, and the indexing afterward:

`STA (\$54),Y`

Things to note:
- The comma denotes indexing (addition)
- The parenthesis denote dereferencing (pointer lookup)
- Indirect, X has the comma inside the parenthesis "(\$54,X)" because the addition is first
- Indirect, Y has the comma outside the parenthesis "(\$54),Y" because the indirection is first

#### yugisokubodai

Danke, I corrected to STA (\$54),y and it works.
I forgot that 65816 doesn't have thing like STA (\$54),x.

I find that STA (\$54,x) works exactly the same as STA \$54,x

#### Disch

QuoteI find that STA (\$54,x) works exactly the same as STA \$54,x

Not at all.

Assume you have the below memory:
`0054=AA0055=BB0056=CC0057=DDX   =02Y   =02DP  =0000`

`STA \$54,X    ; writes to \$0056STA (\$54),Y  ; writes to \$BBACSTA (\$54,X)  ; writes to \$DDCC`

#### yugisokubodai

You deserve my likes