Style Guide for Z80 Assembly Code

Page 5/5
1 | 2 | 3 | 4 |

By pgimeno

Master (230)

pgimeno's picture

14-09-2020, 22:46

ren wrote:

@pgimeno: your 3 indent level alignment example will also fail with space indent. You can't vert. align stuff that's on different indentation levels (if you want to allow for preference size).

Not sure what you mean. Here's both snippets from earlier with spaces:

    if (it_is_true)                  // When true, do something
        for (i = 0; i < 10; i++)     // that loops and performs
            printf("%d\n", i);       // some operations.


    if      COMPARE                  ; Needs a comparison
        ld      b,5                  ; 5 characters to compare
loop:       cp      (hl)             ; Check the character
;     ^^^^ what to use here? spaces or tabs? I used spaces
            inc     hl               ; Prepare next character
            scf                      ; Set error flag
            ret     nz               ; Return error if not equal
        djnz    loop                 ; loop back
    endif
    and     a                        ; Clear error flag
    ret                              ; Return with no error

Yes, it's not adjustable, but it looks correct everywhere, be it terminal, editor, web, or whatever. If someone else starts to hack on this code and uses, say, 2-space indentations, their code will not look consistent with the rest, but it will look self-consistent. A mix of styles is not nearly half bad as wrong indentation. Wrong indentation is even worse than no indentation.

ren wrote:
Quote:

note that browsers use tab stops every 8 columns (like terminals), and that typically makes long lines to get lost or wrapped.

That shouldn't hold one back, there's the CSS tab-size property.

My point is, what should Gogs or Gitea or Gitlab or Bitbucket or Github set it to? Or how can we set it here in this forum, in order to get a certain snippet of code to display with the tab size it was designed to have, while leaving the rest untouched?

The only standard tab size is 8 spaces. And assembler is the only case in which I use tabs. And out of the box, it displays fine here in the forum:

; *** First test ***
; Check how far away from the interrupt we can acknowledge

					; 9T  ; from SyncVInt
		in	a,(99h)		; 12T ; Acknowledge the interrupt that SyncVInt left pending
		ld	hl,_IntSCF	; 11T
		ld	(IntVec),hl	; 17T
		ld	ix,AckAfterInt	; 16T
		ld	(ix+0),22	; 21T ; Start 22 cycles after interrupt (13 for INT in IM1
					;       + 9 for minimal IN, is the fastest it can be
					;       acknowledged in an ISR)

		ld	hl,0-124+22	; 11T ; Cycles used at input time, and starting value of [AckBeforeInt]

Or in e.g. Gogs: https://notabug.org/pgimeno/vdptest/src/master/test-ack-timi...
Or as plain text in a browser, where you don't have CSS: https://notabug.org/pgimeno/vdptest/raw/master/test-ack-timi...

Or in a terminal, except for the fact that some lines get wrapped:

And in your editor if you set it to 8 spaces, which used to be the default setting. Nano still defaults to that, don't know others. Edit: Tested Emacs and Vim, both default to that. SEE.EXE was the one I used for PC-DOS and it also defaulted to that.

By ToriHino

Hero (562)

ToriHino's picture

15-09-2020, 07:27

By Metalion

Paragon (1182)

Metalion's picture

15-09-2020, 08:38

ToriHino wrote:

:P Tabs versus Spaces

You see, I told you about that series ! :)

By ren

Paragon (1495)

ren's picture

15-09-2020, 09:23

Quote:

Not sure what you mean. Here's both snippets from earlier with spaces

I commented on the the first snippet. You're trying to demonstrate what happens when you change indentation level (the number of spaces used) right? For both spaces & tab indent, that has the same effect on the inline comments when you change e.g. from 4 to 2 or whatever.
So what you claim: "This does not happen if the indentation is purely spaces-based." is false. (Or I must be missing something here.. Murdoch )

The 2nd example I can't really comment on as I lack the experience/exposure. FWIW: looks messy/ugly to me with all that whitespace / trying to align in between. With a style like that it indeed does seem you have no choice than to use spaces (or settle on a tab width size).

Quote:

My point is, what should Gogs or Gitea or Gitlab or Bitbucket or Github set it to? Or how can we set it here in this forum, in order to get a certain snippet of code to display with the tab size it was designed to have, while leaving the rest untouched?

True, the browser default is 8. I think these services should offer a tab-width viewing setting when looking at a tab-indented source file and/or a way the author can specify the used tab width size. Adept users can use e.g. a UserScript or -Style to accommodate for this, but that's rather hacky Smile
IMO just like we don't do everything in 80/72 chars/line anymore in 2020, the tab-width property should be regarded as user-adjustable. 4 is most common/preferred nowadays I think?

Anyway, I don't bother too much how browsers render it, most important is how your IDE/editor handles it.

By pgimeno

Master (230)

pgimeno's picture

15-09-2020, 16:01

ren wrote:
Quote:

Not sure what you mean. Here's both snippets from earlier with spaces

I commented on the the first snippet. You're trying to demonstrate what happens when you change indentation level (the number of spaces used) right? For both spaces & tab indent, that has the same effect on the inline comments when you change e.g. from 4 to 2 or whatever.
So what you claim: "This does not happen if the indentation is purely spaces-based." is false. (Or I must be missing something here.. Murdoch )

I still don't get it. If spaces are used, no matter how you change the tab size setting of your editor, the existing spaces won't change. At least not in any editor I have ever used, and there are plenty. Is your experience different?

What I'm trying to demonstrate is that, unless everyone uses the same tab size, using a different tab size or altering the tab size changes how the code is displayed, and that doesn't happen when using spaces instead of tabs, because spaces are always 1 character wide (in monospaced font, of course). And as I said, the only standard tab size is 8, which is typically excessive for languages like C or Lua or Pascal or whatever, but suitable for assembler.

By ren

Paragon (1495)

ren's picture

16-09-2020, 09:53

Ah yeah, I now see your point - I had changing the 'tab'-width/indent size in mind, where you (simply) wanted to demonstrate what can happen when you open/view a file with another tab-width it's authored with. Yes, you can add that to the ++ for spaces Smile

One + for tabs I find it can be quicker to navigate through your source by cursor, and if you somehow mess up the indenting or alignment, it's easier to spot/fix. Of course editors have tools/plugins to aid there, and then there's your linter. In Sublime Text (when not using a linter or similar) I regularly use select all to check my whitespace (would be quite a bit harder when I would be using spaces for indenting).

Btw, I don't have an issue when a format/language dictates spaces, like YAML. (And I like whitespace == formatting / semantic meaning.)

I don't agree e.g. with the blunt/static 8 characters statement in Linux kernel coding style. I do like [q]"if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program."[/q]

My main idea is why uses 4 spaces, when 1 tab does the job. They're perfectly suited for indent, there's only the 8 vs 4 vs 2 issue. Who cares about that ancient 8 char standard when you can agree upon something else? But if you say 8 works for .asm, awesome :)

I do agree on the headache it can give one you've got to deal with inconsistent indented source code.. I remember having to deal with 2 char tab indented code (which I find too tiny), AND author used tabs for v. alignment as well... That's frustrating indeed :) (And then there's the issue of the inline comments which can't be remedied other than by hand..)
OTOH if the author would have used 2 spaces, there still would be the problem of me finding it too tiny (and the inline comments issue)...

Note that (e.g.) GitHub does cater for tab-indent: https://stackoverflow.com/questions/8833953/how-to-change-ta...

Anyway, this thread's topic is "Style Guide for Z80 Assembly Code" and not a generic tabs vs spaces discussion. (I shouldn't be here ;))

-edit: this is nice, perhaps? :) Indentation style (Wikipedia)

By pgimeno

Master (230)

pgimeno's picture

16-09-2020, 16:38

Ok, I'll consider this a middle ground and leave it there, even more so given that it's mostly off topic anyway (though I have tried to keep it as close to the topic as I could). Sorry to have joined the tabs discussion, after more people joined it it became too hard for me to bite my tongue Smile

By ren

Paragon (1495)

ren's picture

16-09-2020, 18:35

No need to apologize, we had some fun right? Smile It was more that I apologized myself for intruding the realm & discussion of the .asm coders here Wink

Oh yeah, @theNestruo: Wink
Yeah, and doesn't matter much for (more or less) private code anyway..
At times I catch myself as well, using tabs where I should use spaces.. (lazyyy) (or can't be bothered) Wink

By Ped7g

Rookie (22)

Ped7g's picture

17-09-2020, 13:45

One trick is to add to your source section with mixed tabs and spaces and make sure it doesn't align completely under any settings of editor, so the readers will fall into despair... Evil

Page 5/5
1 | 2 | 3 | 4 |