Re: converting assembler from one cpu to another ?



Rod Pemberton wrote:
"proteanthread" <rtdos@rtdos> wrote in message
news:RKqdnWRGTLbGFk_YnZ2dnUVZ_qHinZ2d@xxxxxxxxxxxxxx
How hard would it be to convert, say 6502 (or even 6809) assembler to
80x86 assembler in real time (on the fly)? What needs to be considered
? What would be the drawbacks ? Except for emulation / simulation,
what would be the advantages ?


How hard would it be to convert, say 6502 (or even 6809) assembler to
80x86 assembler

This is called binary translation.
(see Wikipedia for more...)

...convert... (on the fly)?

This is called dynamic recompilation.
(see Wikipedia for more...)


Well, I've programmed in many languages including 6502 and x86 assembly. I
haven't seen 6502 assembly in slightly over fifteen years. I learned the
basic (no FPU, no post 486 etc). x86 instruction set fairly recently and
picked up the instructions very easy. So, a large portion of the
instruction set covers the same functionality (although it may be
implemented slightly differently). I do recall the 6502 had zero-page
instructions and a large number of addressing modes, some of which probably
don't exist on the x86. Unlike the 6502, the x86 isn't "orthogonal," i.e.,
certain addressing modes only exist for certain instructions. This could be
one (trivial) problem translating 6502 to x86. The biggest issues with the
x86 was learning about segmentation, protected mode versus real mode, etc.
The 6502 had many working undocumented instructions which weren't mapped to
NOP's and unlike the x86 don't generate any invalid instruction exception.
There where C=Hacking (early '90's online zine) or Transactor articles which
cover this.

In the mid '90's, I saw a C64 emulator that ran well. I don't know what
method they used: interpretation, translation, etc. The early dynamic
recompilers were being developed about that time I saw the emulator (QEMU,
Digital FX!32, etc.). I know the C64 emulator I saw used one technique
which is now called paravirtualization (see Wikipedia). They looked at
which C64 ROM image you were using and then patched it at critical points to
generate an emulator interrupt or emulator escape sequence.

Slightly over two decades ago, I wrote a complete 6502 disassembler in BASIC
which also showed which flags were modified for each instructions. This
allowed one to use different flags as a primitive form of threading. The
disassembler wasn't very large, so I'm fairly sure the code to translate
6502 to x86 wouldn't be all that large either.


What needs to be considered ?
What would be the drawbacks?
Except for emulation / simulation, what would be the advantages ?

Those CPU's (except for special embedded versions) probably never ran much
faster than their original clock frequencies (1Mhz, 2Mhz, 8Mhz etc.) Since
the emulator I saw was running on a DX2-66, the speed of the executed code
shouldn't be a problem for a mid '90's or later x86 CPU's. This means that
you could probably pick any implementation method and get satisfactory
results. I would probably choose the path of least resistance. For me,
that would be a switch statement in C for each of the 256 bytes, with
additional per instruction switches if necessary, a simple virtual software
CPU, and compile the code with various optimizations. Only if the first
attempt code was unsatisfactory would I attempt some rewrites or try to
develop faster helper assembly routines.

An alternate option would be to modify existing open source emulators for
the environment you need. I don't have any links but, when I've searched
for virtual machines, I've seen numerous C64, Apple II, video games (MAME),
Amiga (68000), etc. emulators out there.

Good luck, and let us know...


Rod Pemberton




Hey thanks, Rod; This wealth of information will help me with my OS/Emulator project!

-Woodzy
http://www.rtdos.com
.



Relevant Pages

  • Re: converting assembler from one cpu to another ?
    ... 80x86 assembler in real time? ... I've programmed in many languages including 6502 and x86 assembly. ... picked up the instructions very easy. ... I saw a C64 emulator that ran well. ...
    (alt.lang.asm)
  • Re: B5500 emulation
    ... matter of a few added decimal arithmetic instructions and faster ... I would not bother trying to write an emulator that supports the B5000 ... and somehow obtain their permission to have/use ... simulator/emulator anyway. ...
    (comp.sys.unisys)
  • Re: 50g questions, programming and OS
    ... hardware emulator for the "idealized" intel cpu... ... high level CPU instructions fire small programs inside CPU itself ... Compared to sysRPL instructions which are then interpreted by the CPU core ... Multiple execution cores and instruction decoders (at some point AMD had 3 ...
    (comp.sys.hp48)
  • Re: H-Series Photos
    ... This was to include the H-Series emulator with VULCAN/VOS interception of BLU system service calls. ... - Q register inoperative ... - Interrupt inactive for one instruction on certain instructions ...
    (comp.sys.harris)
  • a simple app embedded CPU emulator to intercept all memory reads/writes
    ... allocations exist at any time. ... Why I thing I need an emulator here? ... CPU simulator allows me to easily track all memory read/write ops - ... So I need to implement a simple CPU instructions simulator. ...
    (comp.lang.asm.x86)