janney@unm-cvax.UUCP (06/09/84)
New information and further reflection have led me to revise my opinion on the feasibility of Pascal and C compilers for the 6502: I've recently had the opportunity to play with Turbo Pascal (1.0) on my father's Z80-based Morrow. Turbo Pascal puts local variables at fixed addresses: if you turn on the compiler option for recursion it saves the old values on a stack at the beginning of every call (just the way you would do in Fortran). The manual implies that this is also done in the 8088 version. As long as they're going to do it that way, there's no reason why there shouldn't be a 6502 version also. Using fixed addresses is a fairly reasonable approach although I think arrays should be exempted for two reasons: You're going to have to calculate addresses anyway It is arrays that are going to occupy lots of memory-- no one is going to declare a hundred different integers. Furthermore, even allocating local variables on a stack is not as bad as I originally thought. True, the 6502 will take more instructions than the Z80 or 6809 BUT-- the instructions are shorter. Consider loading the accumulator with a byte from a location on the run-time stack. Sorry, I'm not familiar with all the assembler conventions, so the instruction formats may not be quite right. processor inst bytes cycles explanation 6502 LDY #offset 2 2 put offset in Y register LDA (ind) Y 2 5 address is contents of Y plus contents of a 16-bit word on page 0 Z80 LD A, (IX+d) 3 5 address is contents of IX register plus an offset specified in the instruction 6809 LDA ??? 3 5 address is contents of one of several registers plus an offset specified in the instruction. A short form can be used if the offset is 5 bits or less. Thus the 6502 takes 4 bytes and 7 cycles where the other cpu's take 3 and 5. This is a noticeable difference, but not the factor of 2 or 3 I had originally suspected. Also, if the needed offset is already in the Y register it doesn't need to be loaded again: this could be used by the += and -= operators in C. The 6502 will be at a disadvantage doing 16-bit arithmetic, since it has no 16-bit instructions. However, the Z80's indexed addressing mode cannot be used with 16-bit instructions (no 16-bit indexed load). Conclusion: compiling Pascal or C for the 6502 is difficult but not out of the question. Jim Janney {{convex,ucbvax,gatech}!unmvax, {purdue,lbl-csam,cmcl2}!lanl-a}!unm-cvax!janney
gwyn@brl-vgr.UUCP (06/10/84)
Since I have (and use) a C compiler on my Apple, I am glad to hear that you have decided that it is possible.