FAILURE MAP
← Case archive

FA-89376 / Instruction set emulation / Open access

Branch target escapes the 16-bit address space · case 01

Branches near address 0 or 0xFFFF produce negative or 17-bit targets.

Verified by executionVariant 1 · 10 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The target is not wrapped to 16 bits.

VERIFIED REPAIR

Wrap the target modulo 0x10000.

Unsuccessful approach: Clamping to the address range is not wrapping.

Case contract

Input [pc, disp, taken] for a 2-byte conditional branch at pc in a 16-bit address space. The next instruction is (pc+2) & 0xFFFF; disp is an 8-bit two's complement offset from that address. Not taken: [next, 2]. Taken: target = (next + offset) & 0xFFFF and cost 3 cycles plus 1 when target and next lie on different 256-byte pages. Return [pc', cycles].

Why this case matters

Branch emulation must use the post-fetch PC, sign-extend the offset and charge page-crossing cycles exactly.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = nxt + off
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
forward branch same page[4115, 3][4115, 3]Passed
backward branch[4209, 3][4209, 3]Passed
most negative displacement[8210, 3][8210, 3]Passed
largest positive displacement[12417, 3][12417, 3]Passed
forward page crossing[4371, 4][4371, 4]Passed
backward page crossing from next page start[16637, 4][16637, 4]Passed
branch not taken[20483, 2][20483, 2]Passed
wrap below zero[-123, 4][65413, 4]Failed
wrap above top[65648, 4][112, 4]Failed
zero displacement taken[24579, 3][24579, 3]Passed

SHA-256 / b13451c81f7bb5971e50edb1b269edfab45e8ed53d5012cfc0d0ad71dc051978

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = min(max(nxt + off, 0), 0xFFFF)
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
forward branch same page[4115, 3][4115, 3]Passed
backward branch[4209, 3][4209, 3]Passed
most negative displacement[8210, 3][8210, 3]Passed
largest positive displacement[12417, 3][12417, 3]Passed
forward page crossing[4371, 4][4371, 4]Passed
backward page crossing from next page start[16637, 4][16637, 4]Passed
branch not taken[20483, 2][20483, 2]Passed
wrap below zero[0, 3][65413, 4]Failed
wrap above top[65535, 3][112, 4]Failed
zero displacement taken[24579, 3][24579, 3]Passed

SHA-256 / df84d70b0bcca70b90e9be8d282083c48833a441e12d69373bd54eab0a0a2f10

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = (nxt + off) & 0xFFFF
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
forward branch same page[4115, 3][4115, 3]Passed
backward branch[4209, 3][4209, 3]Passed
most negative displacement[8210, 3][8210, 3]Passed
largest positive displacement[12417, 3][12417, 3]Passed
forward page crossing[4371, 4][4371, 4]Passed
backward page crossing from next page start[16637, 4][16637, 4]Passed
branch not taken[20483, 2][20483, 2]Passed
wrap below zero[65413, 4][65413, 4]Passed
wrap above top[112, 4][112, 4]Passed
zero displacement taken[24579, 3][24579, 3]Passed

SHA-256 / c9105195e8b3948dc36b6f316f26652052cf634e45e0efb1bdcf6c9e48c4620d

Verification & scope

A deterministic bounded teaching model of one emulator rule; the instruction semantics are a stipulated contract inspired by common ISAs and are not a claim of cycle-exact or architectural conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:51:16.804490+00:00.

Case digest / ed9724b8d73ad1d9721b96c532c6432eabbca52c9c132ddcae05310026d7ea84