ASM6 endian-ness for LDA and CMP

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

Post Reply
User avatar
sailense
Posts: 9
Joined: Wed Mar 14, 2018 6:23 pm

ASM6 endian-ness for LDA and CMP

Post by sailense »

So, I just fixed a bug where my gamestate wasn't being tracked properly. The issue was this:

I have defines for things to make the code more readable:

Code: Select all

STATE_START = $00
STATE_CHARSELECT = $01
STATE_LEVELSTART = $02
STATE_RUNNING = $03
STATE_STATUS = $04
When I do LDA, for example with STATE_RUNNING, it works fine and A = $03. But if I do a compare, like:

Code: Select all

CMP #STATE_CHARSELECT
It seems to expand $03 into $0003 and only loads the high byte. The debugger shows that A gets the proper value of $01 but the compare is done against $00. I fixed it by doing:

Code: Select all

CMP #<STATE_CHARSELECT
My question is: is this the normal behaviour of the assember? Like, is this general to all assemblers and a part of addressing that I'm not aware of or a quirk of ASM6?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 endian-ness for LDA and CMP

Post by tokumaru »

That's not normal at all, and I don't remember ever running into something like this during the long time I used ASM6.
User avatar
sailense
Posts: 9
Joined: Wed Mar 14, 2018 6:23 pm

Re: ASM6 endian-ness for LDA and CMP

Post by sailense »

tokumaru wrote:That's not normal at all, and I don't remember ever running into something like this during the long time I used ASM6.
You're right. I wasn't able to reproduce it and it works fine without specifying the low byte. Chalk this down to me being a newbie and probably having some other issue that was messing with it ;)
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 endian-ness for LDA and CMP

Post by tokumaru »

Maybe you forgot the # and were in fact loading from zero page address $03, which likely contained a zero?
User avatar
sailense
Posts: 9
Joined: Wed Mar 14, 2018 6:23 pm

Re: ASM6 endian-ness for LDA and CMP

Post by sailense »

tokumaru wrote:Maybe you forgot the # and were in fact loading from zero page address $03, which likely contained a zero?
That's actually a likely scenario. I only recently started to grok zero page and direct/indirect addressing.
Post Reply