millfork

Millfork: a middle-level programming language targeting 6502- and Z80-based microcomputers and home consoles

This project is maintained by KarolS

< back to index

8086 support disclaimer

Millfork does not support Intel 8086 directly. Instead, it generates Intel 8080 code and translates it automatically to 8086 machine code. For convenience, most undocumented 8085 instructions and Z80 instructions using IX are also translated.

This means that:

For example, code like

asm {
  LD HL, x
  LD BC, i
  ADD HL, BC
  JP C, skip
  LD A, IX(5)
  LD (HL), A
  skip:
}

is compiled to

  MOV BX, x
  MOV CX, i
  ADD BX, CX
  JNC .next
  JMP skip
.next:
  MOV AL, BYTE PTR [BP+5]
  MOV BYTE PTR [BX], AL    
skip:

Generated assembly output uses Intel 8086 syntax.

Configuring code generation

There are three options that influence the 8086 code generation:

emit_8085 and emit_illegals have effect only together.

Major deficiencies of generated code

Register mapping

The registers are translated as following:

          A → AL  
 B → CH   C → CL   BC → CX  
 D → DH   E → DL   DE → DX  
 H → BH   L → BL   HL → BX  
                   SP → SP
                   IX → BP

The AH register is used as a temporary register for holding the flags.

The SI register is used as a temporary register for holding the address in 8080’s LDAX/STAX (LD (DE),A/LD(BC),A/LD A,(DE)/LD A,(BC) on Z80) and 8085’s undocumented LDSI/SHLX/LHLX (LD DE,SP+n/LD (DE),HL/LD HL,(DE) in Z80 syntax).

The DI register is currently not used.

Future development

There won’t be any major future development related to 8086 support, unless a full 8086 backend that is independent from the 8080 backend is created.

The current solution was developed only as a proof of concept.