Page 1 of 1

ASM6 endian-ness for LDA and CMP

Posted: Thu Mar 22, 2018 4:37 pm
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?

Re: ASM6 endian-ness for LDA and CMP

Posted: Thu Mar 22, 2018 4:40 pm
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.

Re: ASM6 endian-ness for LDA and CMP

Posted: Thu Mar 22, 2018 4:47 pm
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 ;)

Re: ASM6 endian-ness for LDA and CMP

Posted: Thu Mar 22, 2018 5:16 pm
by tokumaru
Maybe you forgot the # and were in fact loading from zero page address $03, which likely contained a zero?

Re: ASM6 endian-ness for LDA and CMP

Posted: Thu Mar 22, 2018 7:08 pm
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.