A small problem with a LDA opcode

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

kuja killer
Posts: 91
Joined: Mon May 25, 2009 2:20 pm

A small problem with a LDA opcode

Post by kuja killer » Mon Oct 30, 2017 2:15 pm

Hello, im posting again with a little tiny problem i have involving Zero Page ... Y register

Sometimes i need to use a LDA "zero page" RAM in some places, which is "B9 xx 00"
the problem is, i cant figure out how to actually do it, cause i always get "incorrect addressing mode" error no matter what i try, how many times i try.

This is for "NESASM 2.51 autoZP" version. i dont know if it's a bug or not. :( The only way i can ever make it work is by manually typing out a .db command with the actual hex numbers.

I tried LDA ($41),y ... LDA [$41],y ... LDA ($41,y) ...LDA [$41,y] ... the weird accented brackets like { and } ...i tried everything i can possibly think of and nothing works :( except just a plain .db only
is there some way to do it ??

Image
Last edited by kuja killer on Mon Oct 30, 2017 2:41 pm, edited 1 time in total.

User avatar
Lazycow
Posts: 98
Joined: Tue Jun 11, 2013 1:04 pm
Contact:

Re: A small problem with a LDY opcode

Post by Lazycow » Mon Oct 30, 2017 2:21 pm

there's no LDY $xxxx,y

kuja killer
Posts: 91
Joined: Mon May 25, 2009 2:20 pm

Re: A small problem with a LDY opcode

Post by kuja killer » Mon Oct 30, 2017 2:26 pm

huh ??
Well it does exist in the NES for reals though :|
Image

or ...just doesnt exist in the NESASM 2.51 "only" ?? :|

lidnariq
Posts: 8792
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: A small problem with a LDY opcode

Post by lidnariq » Mon Oct 30, 2017 2:31 pm

kuja killer wrote: LDY ($41),y ... LDY [$41],y ... LDY ($41,y) ...LDY [$41,y]
Lazycow wrote:there's no LDY $xxxx,y
kuja killer wrote:[Picture of LDA $0041,Y]

User avatar
rainwarrior
Posts: 7681
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: A small problem with a LDY opcode

Post by rainwarrior » Mon Oct 30, 2017 2:38 pm

For a good comprehensive reference on which instructions exist, I recommend this:
http://www.obelisk.me.uk/6502/reference.html#LDY

$B9 is LDA absolute, Y though; it is neither LDY nor zero page. You can point absolute addresses at the zero page if you need to, however.

There is a LDX/STX zero page, Y, which I think is the only instruction with that kind of addressing?

kuja killer
Posts: 91
Joined: Mon May 25, 2009 2:20 pm

Re: A small problem with a LDY opcode

Post by kuja killer » Mon Oct 30, 2017 2:40 pm

oops first of all, sorry i said it wrong when i started this topic, i meant LDA, not LDY, my mistake.
Bottom line, i was trying to get "B9 xx 00" ...like if i try LDA (not y sorry above) ...it'll come out as "B1 41" which is not what i wanted. when it needed to be " B9 "

i supposed i could just do like "LDA label name + $800" to use that so called "mirrored" RAM thing, (so that i can get rid of the raw hex numbers) ??
Last edited by kuja killer on Mon Oct 30, 2017 2:43 pm, edited 1 time in total.

User avatar
Sumez
Posts: 909
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: A small problem with a LDY opcode

Post by Sumez » Mon Oct 30, 2017 2:43 pm

I think this is what you want:

LDA $0041,Y

User avatar
rainwarrior
Posts: 7681
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: A small problem with a LDY opcode

Post by rainwarrior » Mon Oct 30, 2017 2:45 pm

kuja killer wrote:oops first of all, sorry i said it wrong when i started this topic, i meant LDA, not LDY, my mistake.
Bottom line, i was trying to get "B9 xx 00" ...like if i try LDA (not y sorry above) ...it'll come out as "B1 41" which is not what i wanted. when it needed to be " B9 "

i supposed i could just do like "LDA label name + $800" to use that so called "mirrored" RAM thing, (so that i can get rid of the raw hex numbers) ??
On NESASM, I think $B1 should only happen if you put [] around the address?

$B1 is LDA (indirect), Y

Most assemblers use () for indirection syntax, but NESASM uses [] instead.

Edit: apparently this specific version of NESASM uses () instead of [].
Last edited by rainwarrior on Mon Oct 30, 2017 6:19 pm, edited 1 time in total.

tepples
Posts: 21755
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: A small problem with a LDA opcode

Post by tepples » Mon Oct 30, 2017 2:48 pm

LDA $41,Y (B9 41 00) calculates the effective address by adding Y to $0041.

LDA [$41],Y (B1 41) calculates the effective address by reading the bytes at $0042 and $0041, forming a 16-bit number out of them, and adding Y.

If NESASM is assembling LDA $41,Y as B1 41, it is misbehaving. Auto-ZP should not activate for aaaa,Y mode unless the instruction is LDX, which is the only official instruction on the 6502 to have both aaaa,Y and dd,Y versions.

kuja killer
Posts: 91
Joined: Mon May 25, 2009 2:20 pm

Re: A small problem with a LDA opcode

Post by kuja killer » Mon Oct 30, 2017 3:05 pm

hmm yea i get what ya guys are saying.
well.. i guess maybe it is a bug then probably, cause yea i use this type of NESASM's "auto zp" thing so that i dont ever have to type any of those " > arrow " things next to zero page lables and stuff

but i guess it wouldnt work only with the B9 ..but ehh

96 28:009C LDA Test1,y
Incorrect addressing mode! ww

well, this is not very pretty looking but this does work:
I've never once in my life used that "mirrored ram" that goes past $800, like this..

is it "NES Safe" to do this $800 ??

Image
Last edited by kuja killer on Mon Oct 30, 2017 3:18 pm, edited 1 time in total.

User avatar
rainwarrior
Posts: 7681
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: A small problem with a LDA opcode

Post by rainwarrior » Mon Oct 30, 2017 3:09 pm

Yes it's safe but it's "unusual" and there's no reason that this shouldn't produce $B9 $41 $00:
LDA Test1,y

It will only produce $B1 if you put brackets [] in there.

Edit: for this version of NESASM, it is () instead of [].
Last edited by rainwarrior on Mon Oct 30, 2017 6:20 pm, edited 1 time in total.

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: A small problem with a LDA opcode

Post by thefox » Mon Oct 30, 2017 3:26 pm

For reference, he's using this version: http://www.2a03.jp/~minachun/nesasm/nesasm_x86.html

And looks like it has a bug where it refuses to assemble lda $69, y (it says "Incorrect addressing mode!"). It's fine with lda $6969, y.

That version also enables parenthesis () to be used instead of brackets [] in indirect addressing.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

kuja killer
Posts: 91
Joined: Mon May 25, 2009 2:20 pm

Re: A small problem with a LDA opcode

Post by kuja killer » Mon Oct 30, 2017 4:40 pm

yea what fox said, i tried all the "label,y" like rainwarrior said, and tons of different ways, and either end up with B1 ...or "incorrect addressing mode" every time.

so finally i just was like screw it and did the +$800 thing.
I went through and replaced all the ".db $B9, xx, 00" with "LDA label+$800,y" instead ...had about 10 of these throughout a whole lot of ASM files

User avatar
rainwarrior
Posts: 7681
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: A small problem with a LDA opcode

Post by rainwarrior » Mon Oct 30, 2017 6:25 pm

Ah, well that explains the problem. LDA abs, Y is broken in this assembler if the address is less than $100?

I guess the only thing I'd recommend is to report the bug and/or find a better assembler. If using +$800 gets you through your current project, though, that's fine too.

Whenever you use () around the address for LDA it should produce $B1, so that part is working fine. (Sorry I incorrectly said [] before, I didn't realize this was a special version of NESASM.)

kuja killer
Posts: 91
Joined: Mon May 25, 2009 2:20 pm

Re: A small problem with a LDA opcode

Post by kuja killer » Mon Oct 30, 2017 7:12 pm

i would more than love to be able to just fix it myself in this nesasm 2.51, though i dont know any programming languages whatsoever besides NES's 6502 stuff. :|

And since that was made in 2011 apparently...i would not be able to use a different assembler because i have a couple files from the author of Rockman 4 Minus Infinity (puresabe) that i use, ..which were formatted specifically only for NESASM, i dont have a clue how they would be made to work with ASM6 or whatever.

Post Reply