5 ms·
So if C paradigm doesn't fit the Z80 architecture, does anyone know if there's a language (other than Z80 assembler) that does. Or do Z80 enthusiasts generally
by smcl 6y ago
So if C paradigm doesn't fit the Z80 architecture, does anyone know if there's a language (other than Z80 assembler) that does. Or do Z80 enthusiasts generally just write everything in asm?
- zozbot234 6y agoIt's not so much the 'C paradigm' that doesn't fit these machines, but really the ABI features C relies on to support separate compilation units. You could have a C compiler that's restricted to handling complete programs with no "extern" references of any kind (other than those that might be specified by some custom, asm-like mechanism) and it could absolutely match hand-written asm, given a good optimizer.
- monocasa 6y agoAre there any Z80 compilers with link time optimization? This is the exact problem that lto is designed to help with. ie. rather than emitting machine code in the object files (or in addition to), emit compiler IR so you can do additional optimization passes with the whole binary present at link time.
- Gibbon1 6y agoOne C compiler I used 30 years ago sacrificed reentrancy for variable folding. It did call chain analysis so that it could alias local variable and function parameters to single global scratch pad variables. That allowed you to write non trivial programs in C for the 8031/32 without external RAM.
- billforsternz 6y agoI remember using that one as well, Keil right?
- CyberDildonics 6y agoIt is probably pretty realistic at this point to compile any program for a Z80 into a single compilation unit.
- monocasa 6y agoSure, but codebases aren't structured that way.
- megameter 6y agoConcatenate it into an amalgamated unit at build time, then. This only adds a style requirement in that you can't use linking to enforce namespacing.
- monocasa 6y agoTo expect the compiler to take advantage of that, you'd need to mark pretty much every function with static.
- loeg 6y ago-fwhole-program? Or -fvisibility=hidden.
- monocasa 6y agoGCC doesn't have a mature Z80 backend.
- loeg 6y agoI didn't mention GCC in that comment. The concept of default visibility is hardly GCC-specific. Also, it is not clear that the thread is still on the topic of z80 specifically or whole-project LTO generally. If you find yourself doing the latter outside of z80, you may find GCC useful. And hidden visibility is often useful a good default. If you want a z80-specific LTO option, sorry, I'm unfamiliar with any. That's a pretty niche ask.
- kllrnohj 6y agoThe Z80 enthusiasts in the TI-83/84 arena used to just write everything by hand in asm. Although since TI just killed that with their latest OS update, that's going to be a decent chunk of the Z80 enthusiast market gone overnight.
- m0xte 6y agoThere's still a bazillion 83/84 devices out there which have absolutely no way of updating the OS.
- kllrnohj 6y agoEh? The OS can be updated just fine, or are you just saying that all those devices won't be updated instead of can't be updated? Because that's going to be true for the enthusiasts & people no longer going through standardized testing, definitely. For those doing standardized testing, though, it wouldn't be all the much of a shock if tests mandated / provided an update to use the calculator on the test.
- m0xte 6y agoMost of the earlier 83’s had ROMs.
- folmar 6y agoYou can try Copilot https://copilot-language.github.io/ https://copilot-language.github.io/ (which does use C as backend, but this C is restricted to be microcontroller friendly)
- pvg 6y agoTurbo Pascal was born on Z80s. The Turbo Pascal wikipedia page says Anders Hejlsberg released his first Z80 Pascal in 1981. And BASIC, of course, runs on everything.
- masswerk 6y agoWhat about PL/M, the language invented by Gary Kildall in 1973 and used to implement CP/M? (PL/M targets, like CP/M, the 8080 instruction set, of which the Z80 provides a superset.) https://en.wikipedia.org/wiki/PL/M https://en.wikipedia.org/wiki/PL/M
- asplake 6y agoLate 80s and just out of uni I worked on a mature PL/M codebase for flight simulator visual systems. Happy days!
- loeg 6y agoZ80 is just not a great architecture these days so most people would pick a different platform. We have a wealth of other low-powered, cheap 16- or 32-bit microcontroller architectures without the same limitations. Most of the TI-83/84 scene was hand-written z80 assembler.
- siraben 6y agoIt is possible to write a Forth implementation[0] for the Z80 that uses just enough registers to get the execution model on top. [0] https://github.com/siraben/ti84-forth/blob/bc0140d641a121a4f2e43a2ccb796e42d58ead44/forth.asm#L63-66 https://github.com/siraben/ti84-forth/blob/bc0140d641a121a4f...
- Zardoz84 6y agoNot only is possible. Even was a comercial computer using Forth instead of BASIC. And it was pretty similar to the ZX Spectrum... I'm talking about the Jupiter Ace https://en.wikipedia.org/wiki/Jupiter_Ace https://en.wikipedia.org/wiki/Jupiter_Ace Also, there is an obscure french Z80 computer that uses Forth : Hector HRX
- ken 6y agoThere's a number of Forth implementations for 8-bit computers. Chuck Moore has claimed "A Forth application can take 1% the code employed by the same application written in C" [1], which is certainly a big benefit on a small computer. [1]: https://colorforth.github.io/1percent.html https://colorforth.github.io/1percent.html
- Doctor_Fegg 6y agoThere was even one 8-bit machine which shipped with Forth as standard, rather than BASIC: https://en.wikipedia.org/wiki/Jupiter_Ace https://en.wikipedia.org/wiki/Jupiter_Ace
- tluyben2 6y agoI wrote z80 asm from the early 80s to the early 90s and definitely never felt the need to grab for a higher level language. Friends told me to try C/Pascal, but I found them clunky, slow and inefficient. Thing is, you could not write very large programs anyway: I could get up to 128kb but it was very rare to have code that large; most of it was game data for instance. If I would have a Z80 now with megabytes of memory (which I do by the way), I would still write asm for it if the project was for fun; if it were serious, then I would try (probably) a commercial compiler. Maybe Forth, as was mentioned here; I really like Forth and use it on new embedded devices to go spelonking.
- microtherion 6y agoFORTH ran pretty decently on any 8 bit architecture. While probably not great in speed, it generated very compact code, which mattered a lot with memory sizes in those days.