Reconciling register names in Z80 and 8086

Discussion of development of software for any "obsolete" computer or video game system. See the WSdev wiki and ObscureDev wiki for more information on certain platforms.
Post Reply
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Reconciling register names in Z80 and 8086

Post by tepples »

or: Making the the Sega Master System and the PC Master Race System speak the same language

First, there was the Intel 8008, a microprocessor commissioned by Datapoint to run its programmable dumb terminals. Two years later, Intel refactored the design into the 8080 but kept it similar enough to that source code could be translated. Later on, Intel released a revision of the 8080 called 8085, a variant with depletion-mode transistors (to run with only ground and +5 V) and built-in serial ports that powered the Digital VT102 terminal.

At the same time as the 8085's release, Zilog cloned the 8080 as the Z80, with a few more features. Zilog's official syntax differed from Intel's, likely in part for the same reason that Sony's SPC700 syntax differs from that of its Rockwell 65C02 predecessor: fear of a lawsuit that would have been the Oracle v. Google of the times.

While part of Intel was working on iAPX 432, another part was working on a further refactor of the 8085 to compete with the Z80 and 68000, called the 8086. This too included the 8008 and 8080/8085 instruction sets as subsets, allowing translation of assembly language source code with no significant loss (nor gain) in runtime efficiency. But again, the opcodes were renumbered.

The Z80 contains several 8-bit registers (A, B, C, D, E, H, L), plus three dedicated 16-bit pointer registers (IX, IY, and SP). Several pairs of 8-bit registers can be paired to act as additional pointer registers (BC, DE, HL).

The 8086 contains eight 16-bit registers (AX, BX, CX, DX, SI, DI, BP, and SP), plus an instruction pointer and four segment registers. The top or bottom half of each X register could also be used as 8-bit, like half of a Z80 register: AX is AH and AL, etc.

So now my question: Which 8086 register corresponds to each 8080/Z80 register? How did the 8086 assembler map register names when translating 8080 assembly language?
Joe
Posts: 649
Joined: Mon Apr 01, 2013 11:17 pm

Re: Reconciling register names in Z80 and 8086

Post by Joe »

tepples wrote:So now my question: Which 8086 register corresponds to each 8080/Z80 register?
From what I've been able to gather, this is the default mapping:

AL = A
CH = B
CL = C
DH = D
DL = E
BH = H
BL = L

AX = PSW/AF
CX = BC
DX = DE
BX = HL
SP = SP
SI = IX
DI = IY

This mapping requires all accesses of PSW/AF to be wrapped with some combination of LAHF/SAHF/XCHG. The Z80 string instructions would also need to be wrapped with some XCHG instructions to appropriately translate to their 8086 counterparts.
tepples wrote:How did the 8086 assembler map register names when translating 8080 assembly language?
Some translators weren't assemblers. (In my quick search, I didn't come across any 8086 assemblers that accept 8080 assembly input, but I didn't look too hard.)
Post Reply