Creating a data structure.

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

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

Re: Creating a data structure.

Post by Pokun »

I think local labels are fine in asm6 except that you can't mix them with nameless labels (+ and - labels) for some reason. I use local labels most of the time and global labels to create new scopes. I would use nameless labels much more if you just could mix them with local labels.

64tass allows mixing local labels with nameless ones and can do more advanced scopes like ca65. It's a good compromise of an assembler as it has advanced functions like ca65 while it keeps most of the simpleness of asm6 and nesasm (no config files for one thing). I only use 64tass for SNES though as all my NES projects are already in asm6 syntax (and I like asm6 a lot anyway).
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Creating a data structure.

Post by tokumaru »

Pokun wrote: Sun May 30, 2021 11:24 amI think local labels are fine in asm6 except that you can't mix them with nameless labels (+ and - labels) for some reason.
Exactly! And since + and - labels are way more useful, that renders local labels practically useless IMO.
User avatar
Controllerhead
Posts: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Creating a data structure.

Post by Controllerhead »

Pokun wrote: Sun May 30, 2021 11:24 am I think local labels are fine in asm6 except that you can't mix them with nameless labels (+ and - labels) for some reason.
Ah! I think this explains my previous frustrations :roll:
Image
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Creating a data structure.

Post by tokumaru »

I remember modifying ASM6 to not start new scopes on +/- labels, and also adding a BANK property to labels (plus a directive to set the current bank number and an operator to retrieve that property), and that fixed almost all my gripes with that assembler. I hardly use ASM6 these days though...
User avatar
Controllerhead
Posts: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Creating a data structure.

Post by Controllerhead »

tokumaru wrote: Sun May 30, 2021 12:06 pm I remember modifying ASM6 to not start new scopes on +/- labels
That sounds useful. Did it look something like this?

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

Re: Creating a data structure.

Post by Pokun »

Sounds very useful indeed, I always thought this was a bug in asm6, but I guess Loopy might have done it on purpose. The BANK property of labels would also be useful, it sounds like nesasm's BANK() function. Please share the code if you have it. Maybe both upgrades could be incorporated with the asm6f fork.

tokumaru wrote: Sun May 30, 2021 11:41 am
Pokun wrote: Sun May 30, 2021 11:24 amI think local labels are fine in asm6 except that you can't mix them with nameless labels (+ and - labels) for some reason.
Exactly! And since + and - labels are way more useful, that renders local labels practically useless IMO.
I strongly prefer to name things as it makes my code more descriptive. A few things are so generic that you don't want to bother with unique names though, so I really wish I could use nameless labels as well. Especially since there are only two layers of scope (global and local) which tend to force you to use a lot of prefixes and/or suffixes in your local labels, easily turning to label hell in very large and complex routines.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Creating a data structure.

Post by tokumaru »

I don't remember anymore, but it was probably something simple like this. If I'm not mistaken, I actually removed the automatic scope creation altogether and added a "scope" or "local" directive to manually control the start of new scopes. I ended up not sharing this because I figured most people wouldn't like to do this manually.
Pokun wrote: Sun May 30, 2021 1:42 pmI strongly prefer to name things as it makes my code more descriptive.
Me too, which is why I generally name my +/- labels. I only use the nameless versions for nearby branches in the same "block" of code.
A few things are so generic that you don't want to bother with unique names though, so I really wish I could use nameless labels as well.
For a long time I just used +/- labels instead of local labels... The whole point of local labels is being able to reuse the same names over and over, and +/- labels can also be reused freely. For example, this:

Code: Select all

Global0:
@Local:
  jmp @Local

Global1:
@Local:
  jmp @Local
Is functionally the same as this:

Code: Select all

Global0:
-Local:
  jmp -Local

Global1:
-Local:
  jmp -Local
So I see very little reason to use @ labels when +/- ones also allow me to reuse names just fine. The only real drawback I see is when you need to reference a label from both directions, but since +/- labels are unidirectional you need to do something weird like this:

Code: Select all

  bne +Local:
+Local:
-Local:
  jmp -Local
What I really want in an assembler is to combine ASM6's +/- labels with ca65's nameless labels. Something like this:

Code: Select all

  bne :Label+
  beq :Label++
:Label:
  jmp :Label-
:Label:
You use some symbol to identify these "relative" labels (maybe something less confusing than the : I used here) and specify the direction and count in the reference itself, using one or more +/- symbols.
User avatar
Controllerhead
Posts: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Creating a data structure.

Post by Controllerhead »

Pokun wrote: Sun May 30, 2021 11:24 am I think local labels are fine in asm6 except that you can't mix them with nameless labels (+ and - labels) for some reason.
Well now you can :mrgreen:
https://github.com/NESblast/asm6f

Seems like my one liner works after torturing it a fair amount.

freem wrote: Sun May 30, 2021 9:28 am
I submitted a pull request to your repo.

Here's a windows binary in the meantime:
asm6f.zip
(36.47 KiB) Downloaded 53 times
EDIT: Download the next one below
Last edited by Controllerhead on Mon May 31, 2021 11:08 am, edited 1 time in total.
Image
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Creating a data structure.

Post by Garth »

See the post at http://forums.nesdev.com/viewtopic.php?p=183712#p183712 and following posts, about implementing nestable program flow-control structures through macros in assembly language, not needing labels at all (just as you don't need labels for these things in a higher-level language). In most cases, the macros will assemble exactly the same thing you would do by hand (meaning there's no penalty in run speed or memory taken), but you get much better clarity, better maintainability, fewer bugs, and you'll become more productive. It sounds like FrankenGraphics successfully adapted them for asm6, so hopefully you can get the source code from him. In addition to what's linked there, I have a couple of longer examples of their usage in the last 40% of the page in my 6502-oriented article on simple multitasking methods, at http://wilsonminesco.com/multitask/ . The last example is from a work project originally done on a different 8-bit processor, then translated for the article. In looking at it again now, I see it could be made slightly more efficient for 6502; but it should still get the reader's imagination going as to the possibilities. Two-byte variables "ACCa" and "ACCb" are short for "accumulator A" and "accumulator B," variables I needed for the other processor.
http://WilsonMinesCo.com/ lots of 6502 resources
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Creating a data structure.

Post by Pokun »

tokumaru wrote: Sun May 30, 2021 2:15 pm
Pokun wrote: Sun May 30, 2021 1:42 pmI strongly prefer to name things as it makes my code more descriptive.
Me too, which is why I generally name my +/- labels. I only use the nameless versions for nearby branches in the same "block" of code.
Oh I see, I didn't know you could use +/- as named local labels, but then again I've never tried naming +/- labels. The readme just says that any label starting with a + or - is a nameless label, so I guess it makes sense, but it could be made a bit more clear on this.

I guess Asm6 just ignores the name of the label so you still refer to them with +/- even if you name them? Otherwise they would seem pointless.
Example:

Code: Select all

-start:
  lda abc
  beq +   ;skip ahead
  jmp -   ;jump back to start
+skip:
It isn't really nameless if you name it, more of a unidirectional local label. On the other hand if Asm6 ignores everything after the +/- it's basically more or less nameless from Asm6's point of view.


Controllerhead wrote: Sun May 30, 2021 3:40 pm
Pokun wrote: Sun May 30, 2021 11:24 am I think local labels are fine in asm6 except that you can't mix them with nameless labels (+ and - labels) for some reason.
Well now you can :mrgreen:
https://github.com/NESblast/asm6f

Seems like my one liner works after torturing it a fair amount.
Thank you! This would be a great fix!
But it doesn't work for me. DLL error, it seems you built it as dynamic instead of static so some DLLs are now required.
User avatar
Controllerhead
Posts: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Creating a data structure.

Post by Controllerhead »

Pokun wrote: Mon May 31, 2021 9:05 am it seems you built it as dynamic instead of static so some DLLs are now required.
Oops! Sorry, i do not know C well at all. :oops:

I built this with -static -O3 and -march=native. Let me know if it works:
asm6f_210531_1.zip
(39.81 KiB) Downloaded 41 times

PS- Are there other command line options i should be using?

EDIT: added -march=native
Last edited by Controllerhead on Mon May 31, 2021 11:22 am, edited 2 times in total.
Image
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Creating a data structure.

Post by tokumaru »

Pokun wrote: Mon May 31, 2021 9:05 amI guess Asm6 just ignores the name of the label so you still refer to them with +/- even if you name them?
No, it doesn't ignore the name. You have to write the full name to reference these labels (e.g. bne +skip).
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Creating a data structure.

Post by Pokun »

Oh I see, then I misunderstood the usefulness of this. Is the only advantage that they can be combined with nameless +/- labels?
I guess + and - are also easier to type on most keyboards as they don't need any modifier keys. Swedish IBM-PC keyboards requires pressing AltGr+2 which is a bit cumbersome for something as common as labels.

Controllerhead wrote: Mon May 31, 2021 10:45 am
Pokun wrote: Mon May 31, 2021 9:05 am it seems you built it as dynamic instead of static so some DLLs are now required.
Oops! Sorry, i do not know C well at all. :oops:

I built this with -static and -O3. Let me know if it works:
asm6f_static.zip


PS- Are there other command line options i should be using?
Still doesn't work. I'm not exactly an expert myself, but I usually have to use these linker flags to get static linking to work:

Code: Select all

  -static-libgcc -static-libstdc++
The first one is for C and the second for C++, so both may be needed.
User avatar
Controllerhead
Posts: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Creating a data structure.

Post by Controllerhead »

Pokun wrote: Mon May 31, 2021 11:24 am -static-libgcc -static-libstdc++
Ok, i have these options now, but i'm not sure if i believe them: I have been down a rabbit hole of -Bstatic and Wl and trying to statically link everything manually, but, i cant get MinGW64 to cooperate so i'm not sure if this is truly static or not. Let me know if this runs for you:

asm6f_210531_2.zip
(39.81 KiB) Downloaded 48 times
Image
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Creating a data structure.

Post by Pokun »

Nope sorry, still the "msys-2.0.dll" was not found error. The exe is also much larger than the original one at 103 kB instead of 29 kB. Did you really add that much or is there something else wrong with the build?
Sorry I am of little help in this matter.
Post Reply