Style Guide for Z80 Assembly Code

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

By Thom

Hero (636)

Thom's picture

10-09-2020, 12:37

theNestruo wrote:
Metalion wrote:

It's really a matter of personal taste.

Definitely. Taste... and perceived legiblity and readability.

Furthermore, even font and theme matters: I find my own code (that obviously looks perfectly readable to me in my editor) hard to read in GitHub (theme? font rendering? font family/size? lack of italics? everything combined?).
A tall font will favour more horizontal separation; a wide font will increase cohesion within a line and will allow reduce horizontal separation, etc.

Here is a sample of my style.

So you're using this format:

first column: label (on a seperate line)
second column: instruction
third column: parameter(s)

This means a column has to be 8 chars at least, as 'call nz ' (instruction with most characters) needs 7. It makes sense and looks pretty.

BTW, why do you use square brackets [] in stead of ()?

In VS Code I'm using the MSX Z80 Assembly extension by Yeongman Seo, which uses only 2 chars tabs.

By Grauw

Ascended (9268)

Grauw's picture

10-09-2020, 12:44

In the old days I used a style similar to Metalion’s, and I indeed think that style was very common back then. IDEs like Compass and WBASS also kind of enforced it. Because labels had a length limit, you would just match the indentation of the first tab to that. Additionally writing mnemonics in upper-case was quite common back then although I think I stopped doing that after I graduated from WBASS.

But nowadays with infinite length labels and tabs that are 4 columns wide, I changed my style to always have labels on their own line, and just use a space between the mnemonic and argument. Also I write much less comments than I used to back in the day, and when I do I just give them a two-space lead. When aligning them with spaces there is always an instruction that is longer and you have to re-indent all your surrounding comments (or cheat as on the 4th line of Metalion’s snippet), which causes noise in the commit diffs, so I avoid doing that nowadays.

By sd_snatcher

Prophet (3326)

sd_snatcher's picture

10-09-2020, 13:03

IMHO, the main unwritten rule is: TABSTOP = 8. This rule didn't even need to be written in a style guide at that time, because no text editor even had an option to change this as it would break compatibility with the printers. It was standardised.

Everything else is indeed a matter of personal preference. Smile

By Grauw

Ascended (9268)

Grauw's picture

10-09-2020, 13:20

Are we talking about back in the 80s/90s or about now?

Because nowadays a tab stop of 4 or even 2 is much more common in languages overall, and which people use is again a matter of preference. Indentation with spaces as well (but let’s not go there).

And back in the days, at least in Compass iirc the width of the first tab stop depended on the max label length (up to 20 iirc), so you could always write your labels in a column before the code.

By Timmy

Expert (128)

Timmy's picture

10-09-2020, 14:00

I think a lot of a style guide choices is really depending for whom you are writing for.

If you are writing for a person new to Z80, like I did for a tutorial, I'd write in a different style than just for myself.

For example, I could just skip the style altogether and just write more text instead of just some comment inside the code.

What I am trying* to do these days:

* Trying to not use "unofficial" Z80 code like "LD HL,DE" "SUB A,C" "LD A,[3]"
* Using ALLCAPS instead of lowercase. "LD C,L" is faster to read correctly than "ld c,l"
* Using a disassembler to line up the code, if it's for beginners. Some of them even show t-states information.
* If I write for myself, I only leave just enough clues to be able to read it years later, but not much more.

*) I still fail at some of them though.

By theNestruo

Master (177)

theNestruo's picture

10-09-2020, 13:42

Thom wrote:

BTW, why do you use square brackets [] in stead of ()?

Just because I got used to... (maybe because I learnt assembly with asMSX, that favoured [] for indirection and () for mathematical expressions).

Thom wrote:

In VS Code I'm using the MSX Z80 Assembly extension by Yeongman Seo, which uses only 2 chars tabs.

Not sure if the "2 chars tabs" is set by the extension or by your configuration (example workspace configuration with 8 chars tab)

By Metalion

Paragon (1173)

Metalion's picture

10-09-2020, 17:58

You realize we're having a hell of a nerd/geek discussion, right ?
We're not far from jumping into the tab/space debate ...

By Grauw

Ascended (9268)

Grauw's picture

10-09-2020, 20:03

Tabs for life!

By santiontanon

Paragon (1069)

santiontanon's picture

10-09-2020, 22:25

oh, we are really going there aren't we? hahaha How about upper case vs lower case? Wink


Enlighted (6427)

ARTRAG's picture

10-09-2020, 23:14

Lower case !!!

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