News:

11 March 2016 - Forum Rules

Main Menu

[65816]Store indirect problem

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

Previous topic - Next topic

yugisokubodai

I have this in my loop:

LDA $00
STA $1190,x


This works. Then I modified to

LDA #$1190
STA $54
...
LDA $00
STA ($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?

Thank you for reading
兵法の勝ちを取りても
世の海を渡りかねたる
石の船かな

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  :o
兵法の勝ちを取りても
世の海を渡りかねたる
石の船かな

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=AA
0055=BB
0056=CC
0057=DD
X   =02
Y   =02
DP  =0000



STA $54,X    ; writes to $0056
STA ($54),Y  ; writes to $BBAC
STA ($54,X)  ; writes to $DDCC

yugisokubodai

兵法の勝ちを取りても
世の海を渡りかねたる
石の船かな