NESASM3 Doesn't Use Zero-Page?

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

User avatar
67726e
Posts: 129
Joined: Sat Apr 03, 2010 5:45 pm
Location: South Carolina
Contact:

NESASM3 Doesn't Use Zero-Page?

Post by 67726e »

I was a bit curious as to the usage of zero-page addressing by the NESASM3 compiler and after doing a little digging it appears it does not use zero page. I uncovered this:

Code: Select all

AD 03 00
Which is equivocal to:

Code: Select all

LDA $0003
Is there a reason for this or was it a feature that was just didn't get programmed in?
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

I think it requires you to use special syntax with the Low Byte ( < ) operator. Something like #<$40 or something, but this is just what I remember hearing about that tool. I just use ASM6 and not worry about that kind of stuff.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
67726e
Posts: 129
Joined: Sat Apr 03, 2010 5:45 pm
Location: South Carolina
Contact:

Post by 67726e »

Dwedit wrote:I think it requires you to use special syntax with the Low Byte ( < ) operator. Something like #<$40 or something, but this is just what I remember hearing about that tool. I just use ASM6 and not worry about that kind of stuff.
That worked like a charm, although in this situation I was using labels and not simply LDA $40 but either way, putting a < in front of the address like <$40 or <Label makes the compiler use zero-page.

I find it odd that something like that isn't there by default. I mean it isn't all that hard to check if an address is zero-page. I don't suppose NESASM3 is open-source?
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Post by Kasumi »

http://www.nespowerpak.com/nesasm/nesasmsrc.zip

I think bunnyboy's been updating it when the mood strikes him.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Dwedit wrote:I just use ASM6 and not worry about that kind of stuff.
ASM6 will use ZP addressing whenever possible... If you don't want to use ZP addressing, you have to enter the instruction manually or use a mirror. On the NES you can just add $800 to the address, since $0800-$08FF is a mirror of $0000-$00FF.
User avatar
67726e
Posts: 129
Joined: Sat Apr 03, 2010 5:45 pm
Location: South Carolina
Contact:

Post by 67726e »

When would you not want to use zero-page addressing? I mean so far as I know, wouldn't you want to use fastest solution?
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

Kasumi wrote:http://www.nespowerpak.com/nesasm/nesasmsrc.zip

I think bunnyboy's been updating it when the mood strikes him.
The version number went from v2.51 to v3.01, despite that it only seems to be a bugfix for a single bug (a really bad one though).

It's definitely recommended to use ASM6. Especially if you want to release any source codes. NESASM usually works, but is pretty weird as far as assemblers go. I especially never liked ones that require more verbose sources for mundane tasks like that (TASM, WLA-DX are a couple others).
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

67726e wrote:When would you not want to use zero-page addressing? I mean so far as I know, wouldn't you want to use fastest solution?
The only situation I can think of is Self Modifying code, or crazy situations where you are intentionally executing a garbage instruction to avoid a branch.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

I used absolute mode for a zeropage address at least once, in a timed loop where I needed to use up a single CPU cycle. That was pretty much the only way to do that.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Yup, timed code. Using Absolute addressing instead of ZP is the simplest way to waste a single cycle. There might not be much need for that on the NES, but on the Atari 2600 there surely is.

I do have some timed code in my current NES project (because of my NMI handler, which always takes the same amount of time regardless of the tasks it performs), but I don't think I had to use this particular trick.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

I've used zeropage. Last time I checked, LDA [$00] works.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Doesn't NESASM use []s for indirection? The 6502 doesn't have an indirect mode that's not indexed (the 65C02 does, though), so LDA [$XX] should not be a valid instruction. If that's working for you, that's probably just NEASM being weird again. The correct way to use ZP addressing in NESASM is by using "<" before the variable/address.
Last edited by tokumaru on Wed Dec 08, 2010 8:35 pm, edited 1 time in total.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

I am pretty sure. I've never checked the hex with LDA ($00) though so I am not sure it throws ZP into that or not.


I am dumbfounded why assemblers wouldn't support both. If the case is that it doesn't. :/ >.<
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

3gengames wrote:I am pretty sure. I've never checked the hex with LDA ($00) though so I am not sure it throws ZP into that or not.
Wait a minute! Do you use [] or ()? If you are using parenthesis (which NESASM doesn't use for indirection, unlike all other 6502 assemblers), then it's probably generating absolute addressing instructions. For the program logic it makes no difference, so you can't tell unless you look at the binary. LDA $0000 works exactly the same as LDA $00, it just takes longer.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Let me check? I also use []'s. Not (). () don't throw errors, it might ignore them possibly, causing the zeropage value not to be used?

LDA makes $AD 0000, LDA [$00] makes $B200 (Says UNDEFINED and then BRK instructions), LDA ($00) makes $AD 0000, LDA [$00],Y makes $B1 00, LDA ($00),Y makes $B9 0000. And for some reason, when the debugger for FCEUXD look at the LDA ($00),Y it says @ $0000,Y and says it's pointing to location $0000. >.<



I need to make a better test, but that doesn't seem right. :/ I've used ZP though, and it worked. I used [$##]. It even worked on hardware. 0_0
Post Reply