Re: Code translation





Lee Hart wrote:
> from the "was there ever a CPM for..." thread:
> > I have to say, to simulate a Z80 on an 6502 would be a real
> > challange, and if it has been done, I wouldn't be surprised
> > it is extremely slow. 6502 is really limited in registers
> > and instructions compared to the Z80.
>
> This got me to thinking about an old problem again.
>
> When you automatically translate machine code from one CPU to another,
> the results are quite poor. Each instruction in the source code becomes
> multiple instructions of object code. The resulting program runs much
> slower, and takes much more memory.
>
> It's not that one CPU is "inferior" to the other; it doesn't matter much
> which way you go. A 6502 emulating a Z80 might run 10 times slower and
> need twice the memory. But a Z80 emulating a 6502 also runs 10 times
> slower and takes twices the memory.
>
> However, suppose the source program was in some high-level language,
> like C. Compile it for a Z80. Compile it for a 6502. Now the two
> machine-code programs are nearly the same size, and run at nearly the
> same speed. That's because the Z80 and 6502 are roughly equal performers
> (assuming same memory size and same bus cycle rates).
>
Seems to me the implementations of a HLL resolve down to abstract data
types, such as lists, stacks, fifo buffers [a form of list], trees; and
their operators. Those basic data abstractions can be implemented on
most cpu's to varying degrees of success. Hence, the HLL's are
portable.

> Of course we can bury the problem with vast overkill of memory and clock
> speeds; a 4 MHz 64k Z80 system can be emulated by a 400 MHz 64 megabyte
> Pentium PC.
>
> But shouldn't there be a more elegant, efficient solution? What Dr.
> Dobbs used to call "running light without overbyte"? It seems that what
> is needed is a decompiler; a program that disassembles a
> machine-language program for one CPU into some higher-level language,
> and then a recompiler that efficiently recompiles it for a *different*
> CPU.
>
Such as a reverse P-Code Decompiler? That would take a program an
decompile it into P-Code or some such, so you could recompile it for
another processor with a P-Code compiler. The abstract data types
should transfer. So the modern equivalent would be to decompile into a
Java Virtual Machine. Only, you are talking about: source cpu micro
code -> JVM -> target cpu micro code. So you need a decompile to Java,
and a JVM on the target cpu.

> One simple test to see whether this is possible is to ask ourselves, "Is
> it possible for a human to do this job?" I think the answer is "yes". On
> numerous occasions, I have read assembler code for one CPU to understand
> what it does, and then written equivalent code for another CPU that does
> the same thing. But there is *not* a 1:1 correspondence between the two;
> I may have to move things that were in registers into RAM, or reverse
> the byte order, or replaces sequences of instructions with a single
> instruction. It requires intelligence, but is an orderly process.
>
> But I have never a decompiler-recompiler program to do this on an
> automated basis. Has it been done? Has anyone even tried to do it?
> --
> If you would not be forgotten
> When your body's dead and rotten
> Then write of great deeds worth the reading
> Or do the great deeds worth repeating
> -- Ben Franklin, Poor Richard's Almanac
> --
> Lee A. Hart, 814 8th Ave N, Sartell MN 56377, leeahart_at_earthlink.net

.



Relevant Pages

  • Re: Cost of calling a standard library function
    ... > sense, since push Allocates memory, and pop deallocates it. ... Hence, all the CPU does is, basically: ... so forth...it's even possible to get "free" instructions (effectively ... what else is an ASM coder's job? ...
    (alt.lang.asm)
  • Re: Double-Checked Locking pattern issue
    ... The only reason I could think of is writing earlier to memory could save ... register and we could save the register for later use. ... In short, while some CPU can retire four instructions per clock, there ...
    (microsoft.public.vc.language)
  • Re: Rethinking V.M.S
    ... >> initially paging in the program when it starts. ... The CPU always has to do the 1st sentence (dereference ... > to track the physical pages in memory assigned to a process. ... add a few extra instructions to the "invalid memory" trap handler ...
    (comp.os.vms)
  • Code translation
    ... > and instructions compared to the Z80. ... and takes much more memory. ... It's not that one CPU is "inferior" to the other; ... I may have to move things that were in registers into RAM, ...
    (comp.os.cpm)
  • Next July 27: boot failure(hang) on x86_64 box.
    ... Freeing unused kernel memory: 1360k freed ... ACPI: PM-Timer IO Port: 0x488 ... CPU: L2 Cache: 1024K ... # AX.25 network device drivers ...
    (Linux-Kernel)