Is there an easier way to do this?

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
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Is there an easier way to do this?

Post by tokumaru »

Yeah, I miss ASM6's label system after switching to ca65. Local labels are nice, but you still have to worry about uniqueness between non-local labels. Anonymous labels are also great, but having to count labels when referencing them is not editing-friendly, since you need to change multiple references when you add/remove anonymous labels to/from an area that already uses them.

ASM6's temporary labels are free to use like anonymous labels, but they're named, so easier to reference and more readable. The only drawback is that they can only be referenced from one direction (for obvious reasons), so I have found myself in situations where I had to awkwardly use 2 labels to mark a spot:

Code: Select all

  jmp +MyLabel
  (...)
+MyLabel:
-MyLabel:
  (...)
  jmp -MyLabel
I guess that the ideal solution for me would be if you could specify the direction in the reference, while still being able to name the labels freely. Kinda like this:

Code: Select all

  jmp ?MyLabel+
  (...)
?MyLabel:
  (...)
  jmp ?MyLabel-
  jmp ?MyLabel+
  (...)
?MyLabel:
I'm using "?" to identify this type of label in this example, but I'm not sure this would be the best character to use for real.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Is there an easier way to do this?

Post by Pokun »

unregistered wrote: Why does a local label have a longer range than a nameless lable? Local lables and nameless lables both assemble the same way... at least I think so. A bne + and a bne @ both assemble to two bytes. I bet Loopy (asm6 creator) would have made nameless labels work the same as local labels. Please help me to understand what I'm missing Pokun, thanks for helping me! :D :)

edit: + labels don't have to have numbers in them; that is very helpful for me too... the less numbers I have to look at on the screen makes programming assembly easier for me. :)
Maybe range was a bad word. I mean nameless labels are more limited because you can only refer to them in one direction and also you have to count labels from the reference. And also like Tokumaru said, they get in the way when you need to edit the routine because you might have to change multiple nameless labels. For this reason I usually mostly use them for smaller routines when I just want to do really short jumps or branches.

I agree with you about using numbers being pretty stale. But the few times I do is when there are not a lot of them, so @loop1, @loop2 and @loop3 is still OK I think. Other times I'd give them unique names within the routine like @init_loop, @read_loop or @whatever_loop and such. I like label names that are easy to pronounce, somewhat short and descriptive, and I never had problem of thinking of unique descriptive names for either global or local labels (I've still never done a complete large project though).

I sometimes use local labels just to describe a part of code, even though I never refer to it with a jump or branch. Because with the highlighting I made local labels gets a different highlighting color than comments and global labels, they will stand out more and look pretty. An example is the @up label in my input handler I posted earlier in this thread. It's never referred to in the code, it's just there to be consistent with the other local labels and to be descriptive.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Is there an easier way to do this?

Post by Garth »

Does ASM6 really require labels to be on their own line, with nothing following on the same line??
http://WilsonMinesCo.com/ lots of 6502 resources
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Is there an easier way to do this?

Post by dougeff »

Does ASM6 really require labels to be on their own line, with nothing following on the same line??
Why would you think so?

Why would this be a problem, if it were true?
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Is there an easier way to do this?

Post by tokumaru »

Garth wrote:Does ASM6 really require labels to be on their own line, with nothing following on the same line??
I don't​ think so, since you can use .dsb, .dsw, etc. to create variables, for example:

Code: Select all

MyVariable: .dsb 2
And you can also use temporary label like this:

Code: Select all

- lda MyVariable
  beq -
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Is there an easier way to do this?

Post by Garth »

Thanks. I just ask because ASM6 is not one of the several assemblers I've used, but it seem that everyone using it puts labels on their own lines, increasing the number of lines required to write your code, and adding sometimes-undesirable breaks.
http://WilsonMinesCo.com/ lots of 6502 resources
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Is there an easier way to do this?

Post by Pokun »

Labels don't require their own lines in asm6 and unlike ca65 even the colon is optional.

I mostly use a new line because otherwise I would be really limited on the label length. And since I use only two spaces for indention for opcodes it wouldn't really be possible to have more than one character labels (like for a "+" or "-" label) if they didn't have their own lines. This do indeed sometimes leave undesired breaks, but it's often possible to avoid and the benefits greatly outnumbers the drawbacks IMHO.

I learned to use 2 spaces for indentions from my programming teacher in C++ and continued to do so because it's fast, still easy to see and leaves more room for comments. I once used TABs instead of spaces, but they never look the same on different computers so I don't trust TABs anymore. I don't like inconsistent things.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Is there an easier way to do this?

Post by tokumaru »

Pokun wrote:I once used TABs instead of spaces, but they never look the same on different computers
They do if you use editors that let you pick the TAB size! :wink:
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Is there an easier way to do this?

Post by Pokun »

But then you view it in an editor that isn't setup like that and tada it doesn't work. Sometimes TABs will be differently sized on different lines in the same editor even! Really? What's their problem?? All kinds of strange happenings seems to occur when using TABs, so I avoid them and they can't hurt me anymore. Zamamiro!
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Is there an easier way to do this?

Post by FrankenGraphics »

Whose idea was it anyway to make tabs dependent on environment? I get the benefits in layout programs like quark express and inDesign, and full-fledged word processors, but for notepad applications? That's useless compared to having a standardized indentation.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is there an easier way to do this?

Post by rainwarrior »

If you use tabs for left-side indentation only, you can avoid all problems to do with variations in the display of tab widths.

Use spaces instead of tabs for alignment within a row of text, and never try to align stuff vertically from different tab stops; start all rows that need to be vertically aligned at the same tab stop, then spaces after that.

Examples of common mistakes:

Code: Select all

> = tab
. = space

>   don't>  do> this
>   do......do..this

>   dont(>  int.do,
>   >   >   int.this)

>   do(.int.do,
>   ....int.this)
If you make a rigorous habit of it, I find that variable tab stop sizes become a non-issue, and you can retain the advantages of tabs for indent this way. I don't like using spaces instead of tabs just because it means I have to deal with typing and deleting multiple spaces frequently. The editor can usually automate a lot of it, but if not using actual tabs there's always tons of cases where I still have to deal with all those spaces hanging around.

Of course, in a professional setting, or when working with someone else's code, I don't have a choice, I must adopt the prevailing style. If your editor lets you show whitespace characters, I find this is a big help for quickly identifying the style used. (Especially helpful if you can make the whitespace characters a pale colour against the white background.) Also, try to get an editor configurable for tabs vs spaces and different tab stop sizes, if you can.
Last edited by rainwarrior on Wed Apr 05, 2017 10:08 am, edited 2 times in total.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Is there an easier way to do this?

Post by lidnariq »

The tab byte as a nonprinting symbol with meaning, rather than as a nonprinting symbol with constant width, is something I've found useful... and something that python programmers everywhere haven't (but I suspect would), because no more text editors agree on this interpretation than on tab width.

I use 22-character-wide tabs when writing assembly. If I had an editor that would automatically set the first two tab columns according to the width of assembly labels and mnemonics, that would be even better.

I've somehow managed to coax emacs's C-mode into using semantic tabs with spaces for alignment. (i.e.
if (foo &&
␣␣␣␣bar) {
tabstuff();
}
The cool thing about this is that it will render correctly regardless of what the tab width is set to.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is there an easier way to do this?

Post by rainwarrior »

FrankenGraphics wrote:Whose idea was it anyway to make tabs dependent on environment? I get the benefits in layout programs like quark express and inDesign, and full-fledged word processors, but for notepad applications? That's useless compared to having a standardized indentation.
I think there was a tradition of 8 spaces coming from UNIX, but many others (e.g. Microsoft) thought this was too much and went with 4, and this resulted in an eternal schism, I guess.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Is there an easier way to do this?

Post by Garth »

I used the tab character a lot when memory and disc size were a lot more limited; but more recently I've set my editor's (MultiEdit) options to use spaces to bring me up to the next tab column when I press the tab key. It's more of a pain when you want to backspace over it, since you have to backspace varying numbers of times, but the reason I did it was that the tab character was making a mess of vertical alignment when I copy and paste source code into a web page or forum topic.
http://WilsonMinesCo.com/ lots of 6502 resources
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Is there an easier way to do this?

Post by unregistered »

Garth wrote:I used the tab character a lot when memory and disc size were a lot more limited; but more recently I've set my editor's (MultiEdit) options to use spaces to bring me up to the next tab column when I press the tab key. It's more of a pain when you want to backspace over it, since you have to backspace varying numbers of times, but the reason I did it was that the tab character was making a mess of vertical alignment when I copy and paste source code into a web page or forum topic.
Good point! To get around having to backspace varying number of times use Shift+Home then Delete. And I think CTRL+Left will allow you to move the cursor quickly to different words. :)
Post Reply