Hermes wrote:
I think, that passing parameters on a software stack (like in C) is slow, because of the indirection.
They could be passed in a hardware stack - but on the 6502 the hardware stack is somewhat limited, so may restrict things like recursion and so on.
One thing to think about is the case of separately compiled libraries - how else would you pass parameters into them?
Some compilers now are getting "smart" in that if you compile ALL the code as one huge file then they can make some very good optimisations while maintaining the same paradigm you see at the C level. I think LLVM is getting good at this now - the down-side is that newer compilers need new resources to run - faster CPUs, more memory and so on.
Quote:
I thought, that Fortran (up to 77) would be faster, because it does not use the stack. But I was wrong.
Fortran passes parameters by reference. This also includes indirection and is also slow.
When I was at uni (c1980) the big thing then was cross language calling - being able to call FORTRAN from Pascal (and COBOL, but the computer we had then didn't support C) so a common parameter passing method was needed.
And today that's still the case - think of some of the standard numerical libraries (NAG, BLAS, numPy, etc.) which you can call from FORTRAN or C, or ... Pushing parameters (their value or a pointer to their value) on a stack is fairly common. The act of pushing them on is not that slow for a lot of 'real' CPUs - the issue with smaller 8-bit systems like the 6502 is that you often have to (or want to) emulate a software stack, then pushing can become slower.
Right now I'm doing some ARM work at the assembly language level - with ARM you can push any number of registers into the hardware stack with a single instruction although the calling function ABI says that the first 4 parameters are to be passed in registers but it does make setting up the stack relatively easy.
Quote:
After reading more about the 6502 and techniques to pass parameters to subprogramms and how to handle local variables I realized, that parameters and local variables should have fixed adresse (for non recursive functions).
So global variables or the FORTAN (named) COMMON block...
Quote:
This week I discovered that there is at least one (maybe more) C compiler which does this (no stack, no recursion).
Microchip calls that a "compiled stack" for a C compiler for PIC.
Such a C compiler - or a FORTRAN compiler with parameter passing by value (for simple types only) - would suit my needs.
Do look at LLVM... Or consider writing your own... No easy task unless that's your think though (which I suspect it isn't as you're asking here, please correct me if I'm wrong)
Quote:
At
https://dwheeler.com/6502/ I found Slang and Action! Those look like languages that I want to use on the 6502.
Also read his page on language implementation on the 6502 if you've not found it already:
https://dwheeler.com/6502/a-lang.txtHere is something to consider too - if what you want doesn't exist, and you can't write it, then who will write it?
Will they write it for free or reward? If they seek reward might it be simply the fame of doing it, (or e.g. doing it as a personal project then releasing the code for all), or money? Then there's the question of support...
Open source is a funny old thing now.
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/