FA-89366 / Instruction set emulation / Open access
Branch offset applied to the opcode address · case 01
Every taken branch lands two bytes early.
ROOT CAUSE
The displacement is added to the branch opcode address instead of the address after the instruction.
VERIFIED REPAIR
Add the displacement to the address of the next instruction.
Unsuccessful approach: Using pc+1 still lands one byte early.
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 = (pc + 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| forward branch same page | [4113, 3] | [4115, 3] | Failed |
| backward branch | [4207, 3] | [4209, 3] | Failed |
| most negative displacement | [8208, 3] | [8210, 3] | Failed |
| largest positive displacement | [12415, 3] | [12417, 3] | Failed |
| forward page crossing | [4369, 4] | [4371, 4] | Failed |
| backward page crossing from next page start | [16635, 4] | [16637, 4] | Failed |
| branch not taken | [20483, 2] | [20483, 2] | Passed |
| wrap below zero | [65411, 4] | [65413, 4] | Failed |
| wrap above top | [110, 4] | [112, 4] | Failed |
| zero displacement taken | [24577, 3] | [24579, 3] | Failed |
SHA-256 / 4cc6b9455d096136c3007b53e466c44f89e41b60500f6123fc494639a6271468
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 = (pc + 1 + 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| forward branch same page | [4114, 3] | [4115, 3] | Failed |
| backward branch | [4208, 3] | [4209, 3] | Failed |
| most negative displacement | [8209, 3] | [8210, 3] | Failed |
| largest positive displacement | [12416, 3] | [12417, 3] | Failed |
| forward page crossing | [4370, 4] | [4371, 4] | Failed |
| backward page crossing from next page start | [16636, 4] | [16637, 4] | Failed |
| branch not taken | [20483, 2] | [20483, 2] | Passed |
| wrap below zero | [65412, 4] | [65413, 4] | Failed |
| wrap above top | [111, 4] | [112, 4] | Failed |
| zero displacement taken | [24578, 3] | [24579, 3] | Failed |
SHA-256 / e6f4431935cd8726f2344e2fc2416cb980f8cde8537c098b07b4756cf75a28ff
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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.719281+00:00.
Case digest / f77aa4f96b170f0f5961aa8b2dbf4fd5c4afc09fcfbfb025cc923bc76e4d3251