Re: design a simple "bytecode"

From: Ruud_at_Baltissen.org
Date: Wed, 26 Oct 2011 20:03:05 +0200
Message-ID: <4EA84B59.8842.37C1F8@Ruud.Baltissen.org>
Hallo Gábor,


> ... That code must be simple to be translated easily for the
> target CPU with the maximal possible performance ...

Quite some time ago I started to write my own Pascal compiler. The 
idea was that it should at least be capable of compiling its own 
sources. The output would be an assembler file but one only filled 
with macros. The assembler must turn these macros into a binary.

My self programmed assembler is capable of handling various 
processors including the 6502 plus various successors, Z80, 6800 
and 6809. A directive in the Pascal source tells the assembler for 
what machine it was meant. The assembler simply replaced the macros 
with the assembler code found in the macro file made for this 
machine.

And yes, machine, not processor. The idea was to use the onboard 
ROM routines from that machine for certain tasks. If I have to 
output a character to the screen, why not using the routine that is 
already present in the ROM? It surely is the easiest way, if it is 
the fastest, that's another question. If you think the ROM routine 
is too slow, just replace the according lines in the macro file by 
new and better ones and recompile the ASM file.

So far I am able to compile my own sources and I'm quite sure I 
covered all Pascal commands. Better: the ones of Turbo Pascal. Next 
I started to create the macros. And so far I haven't finished the 
one for the C64, it is a lot of work :(

An interesting detail: Pascal pushes a lot of things on the Stack. 
The one of the 6502 is much to small. So I created my own Stack. 
IIRC two locations of the zero page points to this stack. If I have 
to push something on the Stack, I use "sta (zp),Y" (where Y=0) and 
then decrease the pointer. And all this is done inside the macro 
file. 
But the Z80 and 65816 can use all 64 KB as Stack. So the above 
trick isn't needed for these two processors and normal Stack 
operations can be used.

I hope this was clear enough. If not, you know where to find me :)


--
    ___
   / __|__
  / /  |_/     Groetjes, Ruud Baltissen
  \ \__|_\
   \___|       http://Ruud.C64.org







       Message was sent through the cbm-hackers mailing list
Received on 2011-10-26 19:00:22

Archive generated by hypermail 2.2.0.