# Undocumented and undefined behaviour Intel's manual calls a flag "undefined" after some instructions and leaves sixteen opcodes and several ModR/M forms out of its tables. The hardware does something deterministic in every case, and for the first time a hardware-captured corpus records what: the SingleStepTests 8088 v2 README states that "undefined flag state is now correctly captured from the physical CPU", and the 8086 and V20 corpora do the same. This page lists what is known, where it comes from, and what is inferred. **Every rule here is subordinate to the corpus**: if the page and a vector disagree, the vector wins and the page gets fixed. Sources, abbreviated below: - **Intel**: *The 8086 Family User's Manual*, Oct 1979, page labels as printed (see [start-here.md](start-here.md) for the URL). - **NEC**: *V20/V30 User's Manual*, Oct 1986. - **SST-8088**: `README.md` and `v2/metadata.json` of SingleStepTests/8088 at `aea8448` (MIT). `metadata.json` gives each opcode a `status` (`normal`, `prefix`, `alias`, `undocumented`, `undefined`, `fpu`), and where flags are undefined a `flags` pattern over `odiszapc` (letter = undefined, dot = defined) with a `flags-mask` to AND away the undefined bits. - **SST-8086**: the same for SingleStepTests/8086 at `e71c68d`, from an Intel P80C86A-2, a CMOS part. - **SST-V20**: the same for SingleStepTests/v20 at `9efbd02`, from an NEC D70108C-8; adds an `arch` tag (`86`, `186`, `v30`) per opcode. - **MAME**: `src/devices/cpu/nec/necinstr.hxx` and `necinstr.h` at tag `mame0285` (BSD-3-Clause), an emulator's reading, cited only as a detector. Tags: **[hardware]** the corpus captured it; **[documented]** a manual states it; **[unverified]** inferred or reported, not yet checked against a vector. ## Undefined flags ### Where Intel says "undefined" (p. 2-36 to 2-39) and what the corpora mark | Instruction | Intel says undefined | SST-8088 `flags` | SST-8086 | SST-V20 | | --- | --- | --- | --- | --- | | AND OR XOR TEST (08-0D, 20-25, 30-35, 84 85, A8 A9, 80-83 /1 /4 /6) | AF | `.....a..` | same | same | | DAA, DAS (27, 2F) | OF | `o.......` | same | same | | AAA, AAS (37, 3F) | OF SF ZF PF | `o..sz.p.` | same | same | | AAM, AAD (D4, D5) | OF AF CF | `o....a.c` | same | same | | MUL, IMUL (F6/F7 /4 /5) | SF ZF AF PF | `...szap.` | same | same | | DIV, IDIV (F6/F7 /6 /7) | all six | `o..szapc` | same | same | | SHL SHR SAR by 1 (D0/D1 /4 /5 /7) | AF | `.....a..` | same | same | | SHL SHR SAR by CL (D2/D3 /4 /5 /7) | AF, and OF for multi-bit | `.....a..` (v2.0.0) | `o....a..` | `o....a.c` | | ROL ROR RCL RCR by CL (D2/D3 /0-/3) | OF for multi-bit | (none listed) | `o.......` | `o.......` | | IMUL three-operand (69, 6B) | n/a | n/a | n/a | `...szap.` | | Shift/rotate by imm8 (C0/C1) | n/a | alias | alias | C0: as D0; C1: `o.......` for /0-/3, `o....a..` for /4-/7 | | TEST1 (0F 10, 0F 11) | n/a | n/a | n/a | `...szap.` (CY V cleared) | | ADD4S SUB4S CMP4S (0F 20 22 26) | n/a | n/a | n/a | `o..s.ap.` | | INS EXT (0F 31 33 39 3B), BRKEM (0F FF) | n/a | n/a | n/a | `o..szapc` | Readings: the 8088 corpus's metadata (v2.0.0) does not list OF as undefined for counted shifts, while the 8086 corpus (v1.0.1, changelog "added flag mask for D2 and D3") and the V20 corpus do; Intel's text (p. 2-39) says OF is undefined after any multi-bit shift or rotate. The practical rule for a runner: apply the corpus's own `flags-mask` per file, then tighten. The V20 marks CY undefined after counted SHL/SHR/SAR (`o....a.c`) where the 8086 marks only OF and AF; that is a real NEC difference and the V20 corpus is its authority. **[hardware]** for every row's corpus columns; **[documented]** for Intel's column. ### Rules that are known beyond the masks - **Logic ops**: CF = OF = 0 always; AF is what the corpus captured (Intel p. 2-38). **[documented]** for CF/OF. - **NEG**: CF = 1 unless the operand is 0; OF set for −128 / −32768 (Intel p. 2-36). **[documented]** - **INC/DEC** never touch CF (Intel p. 2-35, 2-36). **[documented]** - **Single-bit shifts and rotates**: OF = 1 iff the sign bit changed (Intel p. 2-39). **[documented]** - **CF after a shift** is the last bit shifted out; after a counted shift of 0 nothing changes; the 8086/8088 count is not masked (up to 255 shifts, Intel p. 2-39; SST-8088 masks CL to 6 bits to catch a 5-bit mask). **[documented] [hardware]** - **MUL/IMUL**: CF = OF = "high half significant" (Intel p. 2-37). The captured values of SF ZF PF after MUL follow the low or the full result on the 8088; the corpus decides which and the core should reproduce it rather than mask it. **[unverified]** as a rule; **[hardware]** as data. - **DIV/IDIV**: all six flags come out of the microcode's internal subtract-and-shift loop; SST-8086's README calls reproducing them a "challenge" and points at the microcode. Mask first; reproduce later. **[hardware]** as data. - **REP before IDIV** inverts the sign of the quotient on the 8088/8086 (discovered by reenigne; SST-8088 README, note on F6.7/F7.7; 10 % of IDIV cases carry a REP prefix to test it). REP before IMUL inverts the product's sign on the 8086 (SST-8086 README, not tested there). On the V20, REP before IDIV has no effect (SST-V20 README). **[hardware]** for IDIV on 8088 and V20; **[unverified]** for IMUL. - **Divide error return address**: the pushed CS:IP is the instruction *after* the DIV on the 8086/8088 and V20 (SST-8088 and SST-V20 README). During the exception the flags word pushed onto the stack contains the undefined DIV flags, so a memory-comparing runner must mask that word (SST-8086 README, "Tricky Bits"). **[hardware]** - **AAM imm8 (D4)** divides by the immediate, not by ten; an immediate of 0 raises the type-0 interrupt (SST-8088 README lists D4 among the instructions that "can generate a divide exception"). MAME 0.285's `i_aam` fetches and ignores the byte and divides by 10 (`necinstr.hxx` line 712), which is a documented reason the MAME oracle is a detector only. **[hardware]** for the exception; **[unverified]** that the divisor is used for values other than 0 and 10 (the corpus will settle it). - **PUSH SP** pushes the value of SP *after* the decrement on the 8086/8088 (the 80286 and later push the old value). **[unverified]** here; the `54.json.gz` file settles it in one case. - **The fixed FLAGS bits** 1, 12-15 read as 1 and bits 3, 5 as 0 in every captured flags word of the 8088, 8086 and V20 corpora (checked on `00.json.gz` of each). **[hardware]** ## Undocumented opcodes and forms on the 8086/8088 | Bytes | Behaviour | Source and tag | | --- | --- | --- | | 0F | POP CS. Loads CS from the stack without flushing the prefetch queue, so the next few bytes come from the old segment. | SST-8088 and SST-8086 README (omitted from both corpora, "temporarily" in v2). **[documented by the corpus author, no vector]** | | 60-6F | Aliases of 70-7F: each is the conditional jump at opcode+0x10, because the decoder ignores bit 4 in this range. Real code that targets a V20 (PUSHA etc.) runs as jumps on an 8086. | SST-8088 `metadata.json` `alias` for all sixteen; files `60.json.gz`-`6F.json.gz` present. **[hardware]** | | 82 /r | Alias of 80 /r (the s bit is meaningless for byte operands). | SST-8088 metadata `alias`. **[hardware]** | | C0, C1 | Aliases of C2, C3 (RET imm16, RET). | metadata `alias`. **[hardware]** | | C8, C9 | Aliases of CA, CB (RETF imm16, RETF). | metadata `alias`. **[hardware]** | | D6 | SALC: AL = 0xFF if CF else 0x00, no flags. | metadata `undocumented`; MAME `i_setalc`. **[hardware]** | | D0-D3 /6 | SETMO / SETMOC: the group-2 slot Intel left blank sets the operand to all ones (0xFF or 0xFFFF); flags all undefined on the 8088 (`o..szapc`), on the V20 only AF (`.....a..`, D0/D1) or `o....a.c` (D2/D3). | SST-8088 README ("SETMO and SETMOC"), metadata `undocumented`. **[hardware]** | | F1 | Decoded as a prefix (LOCK's alias: bit 0 ignored). | metadata `prefix` on all three corpora; SST-8088 README: "F0, F1: The LOCK prefix is not exercised". **[documented by the corpus, no vector]** | | F6 /1, F7 /1 | Alias of /0 (TEST imm). | metadata `alias`. **[hardware]** | | FF /7 | Alias of /6 (PUSH r/m). | metadata `alias`. **[hardware]** | | 8C, 8E with REG 4-7 | Only two bits of REG are decoded, so these alias ES CS SS DS. 8E /1 loads CS (without a queue flush). | SST-8088 README. **[hardware]** (random REG values are in the files) | | C6 /1-7, C7 /1-7 | REG is ignored; behaves as MOV r/m, imm. | SST-8088 README ("this field is ignored"), metadata `undefined`. **[hardware]** | | 8D, C4, C5 with mod = 11 | LEA/LES/LDS from a register: leaks the last computed effective address. | SST-8088 README (omitted because the harness's own setup disturbs the last EA). **[documented by the corpus author, no vector]** | | 8F /1-7 | Undefined; "unusual behaviour". | `v2_undefined/8F.json.gz` (SST-8088) holds captured cases. **[hardware, in the supplementary set]** | | FE /2-7 | Undefined: run the FF /2-7 microcode with the width bit clear. | `v2_undefined/FE.2-7.json.gz`. **[hardware, supplementary]** | | FF /2-5 with mod = 11 | Undefined register forms of CALL/JMP far via register. | `v2_undefined/FF.2-7.json.gz`. **[hardware, supplementary]** | | 9B WAIT, F4 HLT, F0 LOCK | Not in any corpus. | SST READMEs. **[documented]** only | | D8-DF | ESC: an EA is computed and, for memory forms, the operand is read; nothing is stored. | metadata `fpu`; Intel p. 2-19. **[hardware]** (files present) | ### Group-2 count masking The 8086/8088 apply the CL count in full: `SHL AL, CL` with CL = 255 does 255 shifts (Intel p. 2-39, "up to 255 shifts"). The corpora mask CL to six bits for test length and say they do so to catch an emulator that masks to five bits (80186 behaviour). The V20 README uses the same words for both CL and the C0/C1 immediate forms, which implies the V20 does not mask either; the V20 corpus is the judge. **[hardware]** as tested (counts up to 63). ## Interrupt-adjacent behaviour that no corpus tests - The one-instruction shadow after MOV/POP to a segment register and after STI/IRET: Intel p. 2-24; NEC p. 6-4 adds MOV reg,sreg and MOV mem,sreg to its list. **[documented]** - A repeated string instruction with more than one prefix resumes after an interrupt with only the last prefix in effect on the 8086/8088 (Intel p. 2-42); the V20/V30 retain up to three prefixes and adjust the pushed return address by one per prefix (NEC p. 6-4). **[documented]** - Neither corpus exercises INTR, NMI, or TF ("the interrupt and trap flags are not exercised"), so all of this is documentation-tier until a hardware-captured interrupt corpus exists. ## The V20/V30 against the 8086: the same bytes, different meanings | Bytes | 8086/8088 | V20/V30 | Source | | --- | --- | --- | --- | | 60-6F | Jcc aliases | PUSHA, POPA, BOUND (CHKIND), 63 undefined-but-harmless ("does nothing, but spends some time doing it"), REPNC, REPC, 66-67 FPO2 (coprocessor), PUSH imm16, IMUL imm16, PUSH imm8, IMUL imm8, INSB, INSW, OUTSB, OUTSW | SST-V20 README and metadata (`arch` 186/v30); MAME `necinstr.h` maps 63, 66, 67 to `i_invalid` | | C0, C1 | RET aliases | shift/rotate by imm8 (count masked to 6 bits by the corpus) | SST-V20 | | C8, C9 | RETF aliases | ENTER (PREPARE), LEAVE (DISPOSE); nesting level not reduced modulo 32 | SST-V20 README | | 0F xx | POP CS | two-byte extended opcodes (bit ops, BCD strings, nibble rotates, bit fields, BRKEM); 0F 20/22/26 with CL = 0 or 255 underflow the loop counter and run 65,535 iterations | SST-V20 README | | D6 | SALC | SETALC, the same | both corpora | | F1 | prefix | prefix | both metadata | | 62 with mod = 11 | Jcc alias | invalid: the V20 halts, with no HALT bus status | SST-V20 README | | FE /3, /5 and FF /3, /5 register forms | undefined | invalid: halt | SST-V20 README | | REP IDIV | quotient sign inverted | no effect | SST-8088 and SST-V20 README | | CMPS under REPE/REPNE | operand access order reversed relative to the unprefixed form | same note made for the V20 | SST-V20 README (A6/A7 note) | | 8E /1 (MOV CS, r/m) | executes, no queue flush | executes, no queue flush; omitted from the V20 corpus because it also confuses the harness | SST-V20 README | MAME 0.285's `nec` core, for the record, treats 63, 66, 67 and F1 as `i_invalid` (10 clocks and a log line), implements SETALC, and marks the MOV-sreg shadow after every MOV to a segment register, POP SS, and LOCK. None of that is evidence; it is what the detector will disagree with.