Style Guide for Z80 Assembly Code

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

By Thom

Hero (636)

Thom's picture

09-09-2020, 14:45

Does a document about coding conventions for Z80 assembly code exist? For other programming languages it does, such as PEP8 for Python. I know it's also a matter of taste, but perhaps there is consensus about the best readability of assembly.

Any ideas?

Login or register to post comments

By Grauw

Ascended (9268)

Grauw's picture

09-09-2020, 16:09

By Metalion

Paragon (1173)

Metalion's picture

09-09-2020, 16:34

I think it's mainly a matter of taste.
There is no universal conventions about coding for Z80.

This is my style :

By santiontanon

Paragon (1070)

santiontanon's picture

09-09-2020, 17:51

I don't think such a guide exists either, but it would be nice if those existed! I'd be interested in it too

By pgimeno

Master (228)

pgimeno's picture

09-09-2020, 18:46

The most common style I've seen is: labels aligned to left margin; 1 tab before instruction, 1 tab between instruction and parameters, no space after comma between parameters, variable number of tabs after last parameter and before the comment (if any) to align all comments together. Pretty much like Metalion's example. When a label is too long to fit in the first 7 spaces, place it in a line alone.

However, I like to use two tabs before the instruction, because it allows for longer labels before needing to place the label in a separate line.

By santiontanon

Paragon (1070)

santiontanon's picture

10-09-2020, 01:12

really? Hmm, I have looked at a LOT of code lately while working on MDL, and Grauw's style above (labels on their own lines, and no tabs between instructions and arguments) is much more common for what I've seen.

I personally find those tabs in between the instruction and the arguments are not the best idea. With the extra separation between instruction/arguments it forces my eyes to do extra effort to map arguments to instructions (maybe you guys have perfect vision, but over the years, my eyesight is not what it used to be, and I need glasses these days). So, the first thing I do when I get a code formatted like that is to remove those tabs to help me read it. I can see it looks pretty, but pretty does not mean "easy to read" (for my eyes at least Smile )

By Ped7g

Rookie (22)

Ped7g's picture

10-09-2020, 02:51

Some Z80 coders follow style enforced by the native tools back from the day, for example in MRS the line was strictly split into columns, labels starting at beginning of line, instruction starting somewhat middle, and arguments further down and finally comment toward end of line... (ie. quite close to what pgimeno described, although "tabs" were not at 8, but at defined positions)

But I wouldn't dare to say "most common", especially now there are many different styles around, depending mostly on personal taste, although some assemblers have requirements as well.

By Metalion

Paragon (1173)

Metalion's picture

10-09-2020, 09:08

santiontanon wrote:

I personally find those tabs in between the instruction and the arguments are not the best idea. With the extra separation between instruction/arguments it forces my eyes to do extra effort to map arguments to instructions (maybe you guys have perfect vision, but over the years, my eyesight is not what it used to be, and I need glasses these days). So, the first thing I do when I get a code formatted like that is to remove those tabs to help me read it. I can see it looks pretty, but pretty does not mean "easy to read"

It's really a matter of personal taste. I need glasses also, and I'm much more comfortable with a tab between opcode and parameters. It helps me get directly to the most important thing of the opcode : its parameters. Contrary to what you've stated, parameters too close to the opcode (just one space) makes the understanding/debugging slower for me.

By santiontanon

Paragon (1070)

santiontanon's picture

10-09-2020, 11:05

Totally agree with the personal thing!

If there is a standard, the most important thing to me would be that it controls the syntax to be used to maximize portability. I've reused code written by other people, and there's usually one or two gotchas of code that compiles when moving it from one compiler to another, but that it is actually interpreted differently (I give examples in the video I mentioned above). So, I'd be all for some "general recommendations" on what and what not to do at the level of syntax (e.g. colon vs not colon in labels, indenting labels or not, etc.), to minimize these gotchas.

But I would not like to tell people where or where not to put tabs, etc.

By theNestruo

Master (178)

theNestruo's picture

10-09-2020, 11:12

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.

By pgimeno

Master (228)

pgimeno's picture

10-09-2020, 12:39

santiontanon wrote:

really? Hmm, I have looked at a LOT of code lately while working on MDL, and Grauw's style above (labels on their own lines, and no tabs between instructions and arguments) is much more common for what I've seen.

Well, I'm talking about code I've seen back in the old days Smile

Starting with the M80 Assembler manual, which may have been influential in propagating that style. The Complete Spectrum ROM Disassembly uses that style too. Also seen in code for 8086 by Borland, by Microsoft and others.

Edit: I haven't talked about letter case. Most of the code I've seen used upper case for everything except comments or text, but that's not a convention I was fond of. I used lower case myself, with labels in Pascal case (aka UpperCamelCase).

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