z00m128/sjasmplus

Support register lists for inc and dec too

sdsnatcher opened this issue ยท 6 comments

The push and pop opcodes can take register lists to save lines.

It would be nice if inc and dec also could take such lists. It would be very useful in a lot of loop endings:

	inc	hl,de,ix,iy,c
	djnz	LOOP

instead of:

	inc	hl
	inc	de
	inc	ix
	inc	iy
	inc	c
	djnz	LOOP

And it's also much clearer to do this:

	inc	hl,hl,hl,hl

than the alternative:

 .4	inc	hl
ped7g commented

multi-arg should work. If you are using --syntax=a, then the double-comma has to be used, ie.
default sjasmplus:

$ sjasmplus --version
SjASMPlus Z80 Cross-Assembler v1.18.3 (https://github.com/z00m128/sjasmplus)
$ echo " inc hl,de,c,b,ix" | sjasmplus - --msg=lst
# file opened: console_input
1     0000 23 13 0C 04   inc hl,de,c,b,ix
1     0004 DD 23
2     0006
# file closed: console_input

and double-comma multi-arg:

$ echo " opt --syntax=a : inc hl,,de,,c,,b,,ix" | sjasmplus - --msg=lst
# file opened: console_input
1     0000               opt --syntax=a
1     0000 23 13 0C 04    inc hl,,de,,c,,b,,ix
1     0004 DD 23
2     0006
# file closed: console_input

Ok, thank you!

The documentation is not very clear on which instructions support multi-arguments, so I thought that inc/dec wouldn't.

ped7g commented

Basically almost all instructions support this (few exceptions don't, but I would need to check source code, which exactly).

But I don't want to promote this feature too much, as in default configuration it's a bit trap-like, something like sub a,h being common issue for new users, or something like rlc (ix+*),h could surprise even advanced Z80 coder, if he forgets about undocummented instructions.

I would still strongly recommend to use --syntax=a to prevent these syntax traps (and get multi-arg result only when you intentionally write double-comma).

closing this for now, as I don't see any "action" to do? Feel free to reopen if you think something should be done.

I totally agree with you about the syntax traps. IMHO, when the comma is used as separator, only the commands that originally took a single parameter should be supported to accept multi-parameter.

To enable the use multi-parameter with other commands, the user should have to select a different separator with --syntax=a

A alternative idea would be disable the ; meaning for comments, and redirect it to multi-separator and whatever other uses a secondary separator is necessary. Comments could still be done with //, /* */ etc.

This would result on a safe and more visually comfortable syntax like:

	ld a,b;c,d;(ix+3),e	// Loads of loads, much easier on the eyes
ped7g commented

yeah, I can see how most of these proposal would work for some people, but they are not easy to implement (the ; would need quite some refactoring, another syntax option to enable multiarg for single-argument instructions is doable, just tedious a bit), and not intuitive to all users and could break old sources.

So at this moment I don't feel like I want to change it, I already did with "syntax=a", which is decent to read inc de,,hl is fine to me, and can't easily clash with old source or other common syntax of other assemblers.

With only-single-arg you will run into strange situations where implicit a can be done explicitly in some other assemblers like sub a,h will be still trap, while sbc will not support multi-arg, etc...

I had several ideas when I was adding double-comma, initially I had even backtick under syntax=A, but these "syntax tuning" options have another disadvantage. Whenever I'm posting some example in forum or issue, or helping with code of some other coder, I have to pick particular configuration. If there are too many syntax options, it will become total mess.

So I have no plan to tune current v1.x... and for hypothetical 2.x I would probably remove multi-args completely, as very useful stuff like push/pop could be then done in macros, if variable arguments for macros are added, and the default syntax of assembler itself can remain simple and without traps. (but I don't plan to work on v2.x in any foreseeable future any way, as v1.x works for me "good enough", these small nags are acceptable to me).

ped7g commented

note: in v1.19.0 some obviously-single-argument instructions will now take single-comma multi-arg even in --syntax=a mode.
Those instructions are: push, pop, inc and dec
(everything else requires double-comma in --syntax=a mode).

This should be safe to not trigger multi-arg by accident, yet convenient to avoid extra commas in stuff like push where there is no implicit/explicit ambiguity.