Command for direct branching in NESASM3 assembler

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
yaofan1212
Posts: 12
Joined: Sat Dec 04, 2021 9:48 am

Command for direct branching in NESASM3 assembler

Post by yaofan1212 »

Hello!

In Ca65 assembler there is a very useful shortcut to branch, is like an anonymous branch:

Code: Select all

       ldy #30 ; 30 rows
	:
		ldx #32 ; 32 columns
		:
			sta $2007
			dex
			bne :-
		dey
		bne :--
Is the colon with the dash: :- or :--

I have tried some combinations of this in NESASM3 but it doesn't work:

Code: Select all

#[1]   .\main.asm
  199  00:C10D                BEQ :+ ;No collision
       Syntax error in expression!
  201  00:C110            +
       Unknown instruction!
Do you know the NESASM3 equivalent? And how this technique is called?

Thanks!
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Command for direct branching in NESASM3 assembler

Post by Banshaku »

Unnamed/anonymous labels is a functionality that is not supported in nesasm.

Some a for, some against so I guess better not start a "war" on the subject :lol:
yaofan1212
Posts: 12
Joined: Sat Dec 04, 2021 9:48 am

Re: Command for direct branching in NESASM3 assembler

Post by yaofan1212 »

Banshaku wrote: Thu Dec 09, 2021 5:44 pm Unnamed/anonymous labels is a functionality that is not supported in nesasm.

Some a for, some against so I guess better not start a "war" on the subject :lol:
Thanks!
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Command for direct branching in NESASM3 assembler

Post by Pokun »

Interesting that you bring this up as the PC-Engine side of Nesasm is about to implement "multi-labels" which seems to me to be the exact same thing as anonymous labels. I'm not sure if the updates works in Nesasm as well though. Pceas and Nesasm is the same assembler and you can switch to the other by renaming "pceas.exe" to "nesasm.exe" and vice versa.
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: Command for direct branching in NESASM3 assembler

Post by Hamtaro126 »

Pokun wrote: Fri Dec 10, 2021 1:57 pm Interesting that you bring this up as the PC-Engine side of Nesasm is about to implement "multi-labels" which seems to me to be the exact same thing as anonymous labels. I'm not sure if the updates works in Nesasm as well though. Pceas and Nesasm is the same assembler and you can switch to the other by renaming "pceas.exe" to "nesasm.exe" and vice versa.
That is not true, PCEAS is sort of compatible with NESASM in that it came from the same assembler family, but got split after the new PCEAS fork split with the NESASM3 version.

The main difference is Hu6280(PCE/TG16) vs 2A03/6502(NES) code that is a bit compatible if using official opcodes, but using unofficial opcodes is incompatible between the two because of extra opcodes replacing the unofficial ones. so be careful.

Also some pseudo-ops between NESASM and PCEAS are different, you are better off converting these on your own

the NESASM3 source can be downloaded HERE

Oh, and for the user who requested help: Hope this works in NESASM:

Code: Select all

	ldy #30 ; 30 rows
PPUloopY:
	ldx #32 ; 32 columns
PPUloopX:
	sta $2007
	dex
	bne PPUloopX
	dey
	bne PPUloopY
AKA SmilyMZX/AtariHacker.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Command for direct branching in NESASM3 assembler

Post by Pokun »

Maybe the NESASM3 fork removed PCEAS but PCEAS never removed NESASM. I've tried it myself in newer versions of PCEAS that comes with HuC.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Command for direct branching in NESASM3 assembler

Post by Garth »

Another way to address the problem and make things more clear is with program flow-control structure macros, eliminating the need for most of the labels, which it looks like you could do in that assembler. This is discussed in these topics:
Is there an easier way to do this?
Question about smoothly handling multiple loops in asm.
6502 coding style.

Hamtaro126, I might write your example code above something like this:

Code: Select all

     FOR_Y  30, down_to, 0
         FOR_X  32, down_to, 0
             STA  $2007
         NEXT_X
     NEXT_Y
It will assemble exactly the same thing you would do by hand. My article on it is at http://wilsonminesco.com/StructureMacros/, and there are longer examples in the last 40% of the simple-multitasking article's page at http://wilsonminesco.com/multitask/ .
http://WilsonMinesCo.com/ lots of 6502 resources
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: Command for direct branching in NESASM3 assembler

Post by Hamtaro126 »

Garth wrote: Sun Dec 12, 2021 6:09 pm Another way to address the problem and make things more clear is with program flow-control structure macros, eliminating the need for most of the labels, which it looks like you could do in that assembler. This is discussed in these topics:
Is there an easier way to do this?
Question about smoothly handling multiple loops in asm.
6502 coding style.

Hamtaro126, I might write your example code above something like this:

Code: Select all

     FOR_Y  30, down_to, 0
         FOR_X  32, down_to, 0
             STA  $2007
         NEXT_X
     NEXT_Y
It will assemble exactly the same thing you would do by hand. My article on it is at http://wilsonminesco.com/StructureMacros/, and there are longer examples in the last 40% of the simple-multitasking article's page at http://wilsonminesco.com/multitask/ .
I already know Macro codes, just chose to do it without macros for once!

EDIT: Removed HuC coding mention, irrelevant to NES side coding!!!
AKA SmilyMZX/AtariHacker.
elmer
Posts: 3
Joined: Sat Apr 22, 2017 11:02 am

Re: Command for direct branching in NESASM3 assembler

Post by elmer »

Hamtaro126 wrote: Sun Dec 12, 2021 1:54 pm That is not true, PCEAS is sort of compatible with NESASM in that it came from the same assembler family, but got split after the new PCEAS fork split with the NESASM3 version.

The main difference is Hu6280(PCE/TG16) vs 2A03/6502(NES) code that is a bit compatible if using official opcodes, but using unofficial opcodes is incompatible between the two because of extra opcodes replacing the unofficial ones. so be careful.
Wow, I didn't know that there were still NESASM users over here, or I'd have come and said "hello" earlier. :D

A quick check of the NESASM3 source (and build) suggests that if really hasn't been changed much since the days of MagicKit, and that the only significant "fix" applied to it was to remove the ability to accidentally use 65C02 opcodes on the NES, that was left in from the PCE side of things.


PCEAS (and consequently NESASM) have moved on quite a bit since then, and anyone still using NESASM for NES development may wish to take a look at the current state of the assembler as it exists within the HuC project, even though you can't use the HuC compiler itself on the NES.

These days the current NESASM will properly error when given 65C02 (or HuC6280) opcodes, and it also supports one of the common syntaxes for the NMOS 6502 "undocumented" opcodes (i.e. ANC,ALR,ARR,AXS,DCP,ISC,LAX,RLA,RRA,SAX,SLO,SRE). That change was made when the assembler was expanded to support developing cartridges for the Atari 8-bit computers.

There are other changes, such as the support of PNG images, the recent addition of "nameless" labels, and many more.

If folks really do want to use the current version of NESASM for actual NES development, then I'll be happy to fix anything that has been broken in it since NESASM3 broke off from the still-developed MagicKit/PCEAS/HuC codebase.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Command for direct branching in NESASM3 assembler

Post by Pokun »

Welcome Elmer!

Yeah NESASM3 is getting a lot of hate due to certain limitations, like the requirement to use 8 kB bank regardless of actual ROM structure. The HuC fork is actively updated and got these kind of things fixed which is why I prefer it.
elmer
Posts: 3
Joined: Sat Apr 22, 2017 11:02 am

Re: Command for direct branching in NESASM3 assembler

Post by elmer »

Pokun wrote: Fri Jan 07, 2022 1:39 pmYeah NESASM3 is getting a lot of hate due to certain limitations, like the requirement to use 8 kB bank regardless of actual ROM structure.
Just to be clear to people not familiar with it ... the NESASM in HuC still only uses 8KB banks, but it freely allows you to overflow code and data from one bank into the next, and there is no longer a hard limit of write-passed-8KB-and-the-build-stops.

That makes it usable (if not perfect) for developing for UNROM or some other mapper that uses 16KB banks.

The question of whether to fully-support different bank sizes hasn't come up yet, but it may become relevent if there are NES developers that want to use the latest NESASM to build code compiled by KickC, which is something that PCEAS now supports as an alternative to using KickC's built-in KickAssembler (which is *very* different to PCEAS and NESASM in handling development for banked-environments).
User avatar
Sivak
Posts: 323
Joined: Tue Jul 17, 2007 9:04 am
Location: Somewhere

Re: Command for direct branching in NESASM3 assembler

Post by Sivak »

One thing you can do are local labels. Just prefix them with a period.

Example:

Code: Select all

Routine:
  ; Some code
.a:
  ;Other code
BNE .a
RTS
-Sivak
Post Reply