z00m128 / sjasmplus

Command-line cross-compiler of assembly language for Z80 CPU.
http://z00m128.github.io/sjasmplus/
BSD 3-Clause "New" or "Revised" License
383 stars 54 forks source link

Add a `dp` declaration to add Pascal Strings #241

Open Cthutu opened 2 months ago

Cthutu commented 2 months ago

Feature overview

I am trying to add strings in my assembly where the first byte is the count of characters in the strings (i.e. Pascal strings). This is really common and often more useful than null-terminated strings.

I propose a new keyword dp that declares a pascal strings. It would concatenate all entries on the line, count the number of bytes they take and emit that count first. Thereafter, it acts like a db declaration.

The count would be stored as a byte so lengths greater than 255 are not allowed. Empty strings should be allowed though.

Examples

    dp "Hello"          ; Equivalent to: db 5,"Hello"
    dp "Foo","Bar"   ; Equivalent to: db 6,"Foo","Bar"
ped7g commented 2 months ago

possible implementation idea: add internal invincible labels (like macro 0> but not listed) to mark start/end of the emitted block so the length byte can be calculated in final pass (even for non-device mode).

note to myself: review which other issues are similar to this, there were multiple attempts for "length of something" directives, usually running into similar implementation problems, doing the internal labels in some general way could maybe solve more of them.