74

Note: This answer mainly focuses on the NES, since that's what I'm most familiar with. Yes; this is called static recompilation or static binary translation, and it is theoretically possible -- jamulator by Andrew Kelly does it. However, recompilation can be incredibly difficult (to the point that falling back to interpretation at runtime may be required ...


73

How was C ported to architectures that had no hardware stack? Simply by implementing a dynamic memory management for subroutine calling, parameter passing and local memory. If there is a known compiler which does anything other than use or implement a stack, Now this is a completely different question than the one made in the headline. Implementing a ...


46

The main downside of "historic" CPU's (non?)-suitability for C programs is the lack of capability to form more than one register into an address without using the ALU. Most more modern CPUs can use base + index + offset register addressing modes to address complex data structures like arrays and structures - The Z80 needs to painstakingly go through the 4-...


43

So you want to write a C program for the IBM PC before the first C compiler for the PC is released. How do you go about it? There are three options I can see: Write your own C compiler Use a cross compiler for 8086 on some other platform Wait for a C compiler to become available Don't use C No four options. Amongst our many options are fear, surprise and ...


43

C didn't spring into being suddenly, but was created by slowly modifying the B language--which was written in itself. Therefore you might say that C was always written in itself, but at first it was just a slightly modified B. Dennis Ritchie describes the evolution of C in The Development of the C Language. He started by making small improvements to the B ...


42

If you try translating C into Z80, you'll see that Z80 index registers and stack don't behave quite as you expect. So, let us begin with Arrays Suppose you have a standard C construction int c[10]; for (int i=0; i<10; i++) c[i]=0; Your compiler is pretty much required to use 16-bit value for i. So, you have &c somewhere, maybe even in your ...


42

Quite often people don't know how to use the compilers or don't understand fully the consequences of code they write. There is optimization going on in the z80 c compilers but it's not as complete as, say, gcc. And I often see people fail to turn up the optimization when they compile. There is an example here in introspec's post that I am not allowed to ...


33

Simple answers one easily gets to this question are The Z80 Sucks and C Sucks - depending on the side someone is on. While they are of course, untrue (*1), there are real issues. A major argument for both sides is that C is at core tied to a PDP-11(ish) CPU architecture and the Z80 isn't one. The Z80 is a rather special CPU, created with a focus on maxing ...


31

One option might have been using “Small C,” which was published in 1980 in Dr. Dobb's Journal magazine. Initially it generated code for the 8080, but was adapted for a few other CPU's. It was adapted to generate code for DOS/8088 but I do not know the date. Small C was written in itself so you would need a CP/M-80 system to do the port. But if I recall ...


30

Yes. For example, the C math library has had full support for long double, which on x87 was 80 bits wide, since C99. Previous versions of the standard library supported only the double type. Conforming C and C++ compilers also perform long double math if you give the operations a long double argument. (Recall that, in C, 1.0/3.0 divides a double by ...


29

The BDS C compiler was released in 1979, ran on CP/M, and was capable of generating code for the Intel 8080 microprocessor. (It also ran on and generated code for the Zilog Z80, but that's not relevant here). This was a very popular, well-known CP/M compiler, and as Wikipedia says: It ran much faster and was more convenient to use than other Z80-hosted ...


27

TL:DR: Yes, most C/C++ compilers other than MSVC expose an 80-bit IEEE754 Extended Precision format (x87, 68881) as long double, and some implementations of other languages have it as REAL10 or whatever name. But no, none of the major C compilers had an option to force promoting double locals/temporaries to 80-bit even across spill/reload, only keeping them ...


22

In the early PC days, letter-writing was still common, and that was at first the main channel of communication to report issues. When CompuServe took off that became the preferred forum, at least in the US. Phone support was also always an option! Here's a typical contact section from a manual, in this case the 1987 Turbo C manual: How to Contact Borland ...


22

Page 198 of that Byte says ZSPL is by Pete Ridley, whose full name appears to be Peter D Ridley, resident at the time in San Diego, California. He and ZSPL are also briefly mentioned in the December 1981 Byte, but I can't find any other trace of them. However, the sample ZSPL code looks rather like the SPL/3000 programming language, introduced in 1972 by ...


21

Places where LLVM will provide no benefit, and may reduce performance: The Z80 has no CPU cache, accessing memory directly instead. Any optimizations based around increasing cache efficiency (eg. aligning sequentially-accessed data to fit in a single cache line, or re-ordering instructions to group common execution paths together) will have, at best, no ...


21

If you want it contemporary, use HiSoft C. Back then the standard compiler and compatible with other HiSoft Tools. For a more up to date and rather comfortable (cross) compiler Z88dk with its Spectrum target might be a good choice. The detailed documentation is a great plus.


20

A full conforming compiler would be impractical, but it would probably be possible to write a compiler for a subset of the language which a couple of features removed: While it would be possible for a compiler to emulate recursion, code that needs to support re-entrancy would likely be much less efficient that code which doesn't. Given that the Standard ...


19

I worked for Borland in the UK doing support for Turbo C 1 to 1.5, most contact was via mail or telephone in those days. Bugs were sent over to the US after we did some triage to check if they could be reproduced, I think it was all stored in Reflex (a Borland produced database) and we got copies of the database periodically. We had Compuserve, MCI mail, ...


19

I believe FORTH Inc. provided the first microcomputer version: FORTH, Inc.'s microFORTH was developed for the Intel 8080, Motorola 6800, and Zilog Z80 microprocessors starting in 1976. Ref It wasn't until 1978 that the FIG-Forth model became available, based on the 6502 implementation developed by one of FIG's founders, Bill Ragsdale. Ref My ...


17

I've seen three common approaches to handling that: The first approach is to have the compiler statically allocate an area of memory for use as a stack, and maintain a global pointer to the current "stack pointer". On a platform with a subroutine call/return stack that's too small to accommodate expected function nesting, something like: int foo(int a, ...


16

I worked for Borland back in the days of the 8086/8087. Back then, both Turbo C and Microsoft C defined long double as an 80-bit type, matching the layout of Intel's 80-bit floating-point type. Some years later, when Microsoft got cross-hardware religion (maybe at the same time as they released Windows NT?) they changed their compiler to make long double a ...


13

Old question, but: I've just shipped an interpreter for a large subset of COMIT. Here it is. http://www.catb.org/esr/comit/ Full documentation is included. There's a pretty good suite of regression tests included. Some routing commands, subroutines, and subscripts are not yet implemented. This is mainly because it's not easy to tell from the manual what ...


13

The problem is that the emulator is emulating a LOT more than just the CPU. So in addition to transpiling the 6502 code to Intel code (and don't think that's simple - making the timing come out right would be a fascinating problem), you also need to provide code (analogous to the standard libraries that any program uses) that provide an emulated I/O ...


12

(speculation, but I'm pretty confident in it) Assuming \/ and /\ were actually used in early C to be max and min, someone probably quickly realized how totally stupid that symbology is. They look like the long-accepted boolean operators for OR (∨) and AND (∧). Having something you've been taught since high school means AND now stands for min in C would ...


11

The 32V paper, A UNIX™ Operating System for the DEC VAX-11/780 Computer (by Thomas B. London and John F. Reiser) has a few interesting tidbits about c2. Two features of the VAX-11 architecture — three-address instructions and indexed addressing mode — were difficult to model within the basic structure of the compiler. The full ...


10

A possible answer is cross-development. If C is the right language for the job, then a prototype can be written in C on any platform that already has it (say, PDP-11, also a little endian 16-bit architecture, with a well-established C environment). A command-line program would be portable enough, maybe with a few include file modifications and taking care of ...


10

As is evident from its name, YACC (Yet Another Compiler Compiler) was not the first compiler writing aid. Its predecessor was the TMG tool. TMG was the compiler definition tool used by Ken Thompson to write the compiler for the B language on his PDP-7 in 1970. B was the immediate ancestor of C. The tmg executable can still be seen on the UNIX V6 disks, ...


9

Z88DK is a suite of development tools for Z80 targets that includes a couple of different C compilers (one a variant of Small C and one a patched version of SDCC) and an assembly-level optimizer that is run as a post-filter on the output of these compilers. It also has a highly hand-optimized library. They've published a set of benchmarks versus some ...


9

From the Gforth manual section Appendix B Authors and Ancestors of Gforth: A team led by Bill Ragsdale implemented fig-Forth on many processors in 1979. Robert Selzer and Bill Ragsdale developed the original implementation of fig-Forth for the 6502 based on microForth. The principal architect of microForth was Dean Sanderson. microForth was FORTH, ...


Only top voted, non community-wiki answers of a minimum length are eligible