ASM6 local label vs nameless label issue

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
Nathonion
Posts: 4
Joined: Tue Jul 18, 2017 5:35 am

ASM6 local label vs nameless label issue

Post by Nathonion » Sat Feb 13, 2021 2:23 pm

I've just started programming with asm6, and I noticed an odd behavior. Here it is in psudocode:

Code: Select all

globalLabel:
@localLabel:
-	someOpcode
	generalBranch -
	jmp @localLabel
That's a basic summary of the code I have right now. What's happening is when asm6 tries to assemble into a .bin, it give an error saying "Unknown label." Reading the readme that comes with asm6, it says that local labels only exist between global labels, so I'm wondering, are the nameless labels global? If you're sure that isn't the case, here's the code in full:

Code: Select all

	; HEADER
	INES_MAPPER = 0 ; 0 = NROM
	INES_MIRROR = 1 ; 0 = horizontal mirroring, 1 = vertical mirroring
	INES_SRAM   = 0 ; 1 = battery backed SRAM at $6000-7FFF
	
	.db 'N', 'E', 'S', $1A ; ID 
	.db $02 ; 16k PRG bank count
	.db $01 ; 8k CHR bank count
	.db INES_MIRROR | (INES_SRAM << 1) | ((INES_MAPPER & $f) << 4)
	.db (INES_MAPPER & %11110000)
	.db $0, $0, $0, $0, $0, $0, $0, $0 ; padding
	.fillvalue $ff
	
	.enum $0000
isVBlank:	db 0;
	.ende
	
	.enum $0300
Sprite0_Y:	.db 0	; sprite #0's Y value
Sprite0_T:	.db 0	; sprite #0's Tile Number
Sprite0_S:	.db 0	; sprite #0's special byte
Sprite0_X:	.db 0	; sprite #0's X value
	.ende
	
	.base $8000
; FamiStudio config.
FAMISTUDIO_CFG_EXTERNAL     = 1
FAMISTUDIO_CFG_NTSC_SUPPORT = 1
FAMISTUDIO_USE_PITCH_TRACK  = 1

; ASM6-specific config.
FAMISTUDIO_ASM6_ZP_ENUM   = $0000
FAMISTUDIO_ASM6_BSS_ENUM  = $0200
FAMISTUDIO_ASM6_CODE_BASE = $8000

    .include "include\famistudio_asm6.asm"
	
VBlank_Routine:
	; Start of function to execute on VBlank
	inc isVBlank	; add one to VBlankOrNo, will be 1 if Vblank, 0 if not.
	rti
	
Start:
	; Init PPU
	lda #%10001000
	sta $2000
	lda #%00011110
	sta $2001
	
	; Init Palette
	lda #$3F
	sta $2006
	lda #$00
	sta $2006		; Where to store the palette in PPU
	ldx #$00
-	lda ourpal, x	; loop through every palette color
	sta $2007		; store color into PPU
	inx
	cpx #32
	bne -
	
	; Init bkg Map
	lda #$20
	sta $2006
	sta $2006
	ldx #$00
-	lda ourMap, X	; load A with a byte from address (ourMap + X)
	inx
	sta $2007
	cpx #128		; map in previous section 64 bytes long
	bne -			; if not all 64 done, loop and do some more
	
	; Init Sound
	lda #%0
	sta $4015
	lda #$40
	sta $4017
	
	; Init Vars
	lda #80
	sta Sprite0_X
	sta Sprite0_Y
	lda #$01
	sta Sprite0_T
	
	; Init Music
	lda #1
	ldx #<untitled_music_data
	ldy #>untitled_music_data
	jsr famistudio_init
	lda #0
	jsr famistudio_music_play
	
@infin:
	; Get Input
	lda #$01
	sta $4016
	lda #$00
	sta $4016
	lda $4016	; A key
	lda $4016	; B key
	lda $4016	; Select key
	lda $4016	; Start key
	lda $4016	; Up key
	and #1
	beq +
		dec Sprite0_Y
+	lda $4016	; Down key
	and #1
	beq +
		inc Sprite0_Y
+	lda $4016	; Left key
	and #1
	beq +
		dec Sprite0_X
+	lda $4016	; Right key
	and #1
	beq +
		inc Sprite0_X
+	
	; Wait for VBlank
-	lda isVBlank	; A = isVBlank
	cmp #1			; if A == 1 then is VBlank
	bne -			; if not VBlank, then loop and do again
	dec isVBlank	; isVBlank--. isVBlank will be 0 again.
	
	; Draw Sprite
	lda #$3		; Copy sprite info to OAM mem in PPU
	sta $4014
	
	jmp @infin
	
ourpal:	; The palette
	.db $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$00  ;background palette data
	.db $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C  ;sprite palette data
ourMap:	; The bkg Map
	.incbin "incbin\bkgMap.map"
	
	.org $a000
song_testMusic:	.include "include\testSong.asm"
	
	; Vectors
	.org $fffa
	.dw VBlank_Routine	; address to execute on VBlank
	.dw Start			; address to execute at RESET.
	.dw 0				; address to execute during a BRK instruction (Another Day, Another time).
	
	; CHARS
	.incbin "incbin/bkg.chr"
	.incbin "incbin/spr.chr"
The error is occurring at the line, "jmp @infin." If I'm missing something, please let me know!

User avatar
dougeff
Posts: 2821
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: ASM6 local label vs nameless label issue

Post by dougeff » Sat Feb 13, 2021 3:05 pm

Yes, the unnamed labels are screwing up the local labels. Replace the unnamed label with a local label.

Code: Select all

globalLabel:
@localLabel:
@1:	someOpcode
	generalBranch @1
	jmp @localLabel
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
tokumaru
Posts: 12000
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: ASM6 local label vs nameless label issue

Post by tokumaru » Sat Feb 13, 2021 3:16 pm

Yeah, I always hated this about ASM6... + and - labels DO start a new local label scope, rendering local labels useless.
dougeff wrote:
Sat Feb 13, 2021 3:05 pm
Replace the unnamed label with a local label.
I actually did the opposite and started using + and - labels for local labels. The only real drawback was when I had to reference a "local" label from both directions, I had to do something weird like this:

Code: Select all

+Label:
-Label:
Except for this weird situation, + and - labels are way more useful than @ labels, IMO.

IIRC you can easily modify this on the assembler's source code, commenting the line that starts a new scope when +/- labels are defined or something like that.

Nathonion
Posts: 4
Joined: Tue Jul 18, 2017 5:35 am

Re: ASM6 local label vs nameless label issue

Post by Nathonion » Sat Feb 13, 2021 4:23 pm

Well, that's unfortunate. At least there's a workaround:
tokumaru wrote:
Sat Feb 13, 2021 3:16 pm
I actually did the opposite and started using + and - labels for local labels.
Thanks for that suggestion, I think I'll try it. BTW, I really appreciate the quick responses, you don't see that in many other forums. :lol:

User avatar
Controllerhead
Posts: 214
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: ASM6 local label vs nameless label issue

Post by Controllerhead » Sat Feb 13, 2021 4:37 pm

Nathonion wrote:
Sat Feb 13, 2021 2:23 pm
I've just started programming with asm6
I would highly recommend ASM6F. It's a fork with more functionality.
https://github.com/freem/asm6f/tree/master

The killer feature is exporting labels directly to the Mesen debugger:
Image

EDIT: Have a windows binary:
asm6f-latest.zip
(70.72 KiB) Downloaded 15 times
Image

Pokun
Posts: 1753
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: ASM6 local label vs nameless label issue

Post by Pokun » Sun Feb 14, 2021 11:05 am

Asm6f doesn't fix the problem in the topic, but yeah it's the definitive version of asm6.

I was pleasantly surprised that 64tass (which I currently use for SNES development) does support mixing local and anonymous labels this way. I probably won't switch from asm6 to 64tass for NES development anytime soon, but it is a good example of how a good assembler should handle this.

unregistered
Posts: 1126
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: ASM6 local label vs nameless label issue

Post by unregistered » Mon Feb 15, 2021 9:24 am

This is why my functions that use local labels are entirely filled with local @ labels. :)

Pokun wrote:
Sun Feb 14, 2021 11:05 am
Asm6f doesn't fix the problem in the topic, but yeah it's the definitive version of asm6.
How could you forget about asm6_? Every assembly I run uses the -U flag. That’s extremely helpful, for me at least, bc the listing file isn’t as huge. :D

A word of caution: asm6_ rarely assembles corrupt .nes files. “rarely” means that it has been set up to assemble files under some unique error circumstances; obviously, asm6 doesn’t assemble corrupt .nes files bc it, instead, doesn’t produce anything; I wanted to debug a program that wasn’t being assembled. This was done on purpose, but I haven’t remembered how to undo those changes. But, it, asm6_, is an extremely helpful version of asm6 to me. :)

Pokun
Posts: 1753
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: ASM6 local label vs nameless label issue

Post by Pokun » Mon Feb 15, 2021 10:41 am

Oh I didn't know about your fork until now. If it's a useful feature, and if you could squish that bug about assembling corrupt outputs, maybe you could contribute it to asm6f.

unregistered
Posts: 1126
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: ASM6 local label vs nameless label issue

Post by unregistered » Mon Feb 15, 2021 1:31 pm

Hmmm... it’s not a bug; rather, it’s an intentional feature that I gave up trying to remove. And I’ve already tried to add asm6_’s flags to asm6f, but the creator never used the code I submitted, I guess. :) asm6_’s flags are super helpful, to me at least; it’s the assembler I always use now.

Believe I submitted the code as user icypawn. (I don’t need asm6f’s auto setup for Mesen; I prefer to do that work myself. :) )

Post Reply