{"abstract":"An addition that lands exactly on 0xFF reports carry.","category":"Instruction set emulation","checks":9,"contract":"Input [a, c, ops] for an 8-bit accumulator with carry c; V starts 0. adc m: s = a+m+c, A = s & 0xFF, C = s > 0xFF, V = signed overflow of the 8-bit add. sbc m is adc of (m xor 0xFF) with the same carry (carry set means no borrow). cmp m: C = a >= m (unsigned), N/Z from (a-m) & 0xFF, A and V unchanged. After each op report [A, N, V, Z, C] where N is bit 7 and Z is result == 0.","evaluation_group":"w2-instruction-set-emulation-adc-sbc-flags","failed_approach":"Comparing the result to the old accumulator misses the carry when m+c is exactly 0x100.","family":"w2-instruction-set-emulation-adc-sbc-flags-carry-out-threshold","id":"FA-89351","implementations":{"attempt":{"sha256":"55aa73ace1f4761683c44381cc06ebfd59a4ef0e7ca6d270b718f5071403afbe","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(*args):\n    a, c, ops = args\n    v = 0\n    out = []\n    for op, m in ops:\n        if op == 'cmp':\n            r = (a - m) & 0xFF\n            c = int(a >= m)\n            out.append([a, r >> 7, v, int(r == 0), c])\n            continue\n        if op == 'sbc':\n            m = m ^ 0xFF\n        s = a + m + c\n        r = s & 0xFF\n        v = int(((a ^ r) & (m ^ r) & 0x80) != 0)\n        c = int(r < a)\n        a = r\n        out.append([a, r >> 7, v, int(r == 0), c])\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('adc without carry', [17, 0, [['adc', 32], ['adc', 5]]], [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 145]]], [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 254]]], [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 126]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [127, 0, [['adc', 128], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [56, 1, [['adc', 255]]], [[56, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [81, 0, [['sbc', 16], ['sbc', 63]]], [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 62], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 193]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [18, 0, [['adc', 32], ['adc', 5]]], [[50, 0, 0, 0, 0], [55, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 146]]], [[160, 1, 1, 0, 0], [50, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 253]]], [[0, 0, 0, 1, 1], [254, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 125]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [242, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [126, 0, [['adc', 129], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [57, 1, [['adc', 255]]], [[57, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [82, 0, [['sbc', 16], ['sbc', 63]]], [[65, 0, 0, 0, 1], [2, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 61], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 194]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [19, 0, [['adc', 32], ['adc', 5]]], [[51, 0, 0, 0, 0], [56, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 147]]], [[160, 1, 1, 0, 0], [51, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 252]]], [[0, 0, 0, 1, 1], [253, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 124]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [243, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [125, 0, [['adc', 130], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [58, 1, [['adc', 255]]], [[58, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [83, 0, [['sbc', 16], ['sbc', 63]]], [[66, 0, 0, 0, 1], [3, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 60], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 195]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [20, 0, [['adc', 32], ['adc', 5]]], [[52, 0, 0, 0, 0], [57, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 148]]], [[160, 1, 1, 0, 0], [52, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 251]]], [[0, 0, 0, 1, 1], [252, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 123]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [244, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [124, 0, [['adc', 131], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [59, 1, [['adc', 255]]], [[59, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [84, 0, [['sbc', 16], ['sbc', 63]]], [[67, 0, 0, 0, 1], [4, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 59], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 196]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [21, 0, [['adc', 32], ['adc', 5]]], [[53, 0, 0, 0, 0], [58, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 149]]], [[160, 1, 1, 0, 0], [53, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 250]]], [[0, 0, 0, 1, 1], [251, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 122]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [245, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [123, 0, [['adc', 132], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [60, 1, [['adc', 255]]], [[60, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [85, 0, [['sbc', 16], ['sbc', 63]]], [[68, 0, 0, 0, 1], [5, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 58], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 197]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"c2f90a5e0bb9cf32570eb48b4a014031c46834f308c367eb59f33a596ad6beb5","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(*args):\n    a, c, ops = args\n    v = 0\n    out = []\n    for op, m in ops:\n        if op == 'cmp':\n            r = (a - m) & 0xFF\n            c = int(a >= m)\n            out.append([a, r >> 7, v, int(r == 0), c])\n            continue\n        if op == 'sbc':\n            m = m ^ 0xFF\n        s = a + m + c\n        r = s & 0xFF\n        v = int(((a ^ r) & (m ^ r) & 0x80) != 0)\n        c = int(s >= 0xFF)\n        a = r\n        out.append([a, r >> 7, v, int(r == 0), c])\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('adc without carry', [17, 0, [['adc', 32], ['adc', 5]]], [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 145]]], [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 254]]], [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 126]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [127, 0, [['adc', 128], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [56, 1, [['adc', 255]]], [[56, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [81, 0, [['sbc', 16], ['sbc', 63]]], [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 62], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 193]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [18, 0, [['adc', 32], ['adc', 5]]], [[50, 0, 0, 0, 0], [55, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 146]]], [[160, 1, 1, 0, 0], [50, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 253]]], [[0, 0, 0, 1, 1], [254, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 125]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [242, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [126, 0, [['adc', 129], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [57, 1, [['adc', 255]]], [[57, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [82, 0, [['sbc', 16], ['sbc', 63]]], [[65, 0, 0, 0, 1], [2, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 61], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 194]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [19, 0, [['adc', 32], ['adc', 5]]], [[51, 0, 0, 0, 0], [56, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 147]]], [[160, 1, 1, 0, 0], [51, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 252]]], [[0, 0, 0, 1, 1], [253, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 124]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [243, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [125, 0, [['adc', 130], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [58, 1, [['adc', 255]]], [[58, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [83, 0, [['sbc', 16], ['sbc', 63]]], [[66, 0, 0, 0, 1], [3, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 60], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 195]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [20, 0, [['adc', 32], ['adc', 5]]], [[52, 0, 0, 0, 0], [57, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 148]]], [[160, 1, 1, 0, 0], [52, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 251]]], [[0, 0, 0, 1, 1], [252, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 123]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [244, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [124, 0, [['adc', 131], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [59, 1, [['adc', 255]]], [[59, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [84, 0, [['sbc', 16], ['sbc', 63]]], [[67, 0, 0, 0, 1], [4, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 59], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 196]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [21, 0, [['adc', 32], ['adc', 5]]], [[53, 0, 0, 0, 0], [58, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 149]]], [[160, 1, 1, 0, 0], [53, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 250]]], [[0, 0, 0, 1, 1], [251, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 122]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [245, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [123, 0, [['adc', 132], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [60, 1, [['adc', 255]]], [[60, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [85, 0, [['sbc', 16], ['sbc', 63]]], [[68, 0, 0, 0, 1], [5, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 58], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 197]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"58a4c81da0eb7d88650983228bfe73501050a0d7ba3958d61a2761d574d0f53f","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(*args):\n    a, c, ops = args\n    v = 0\n    out = []\n    for op, m in ops:\n        if op == 'cmp':\n            r = (a - m) & 0xFF\n            c = int(a >= m)\n            out.append([a, r >> 7, v, int(r == 0), c])\n            continue\n        if op == 'sbc':\n            m = m ^ 0xFF\n        s = a + m + c\n        r = s & 0xFF\n        v = int(((a ^ r) & (m ^ r) & 0x80) != 0)\n        c = int(s > 0xFF)\n        a = r\n        out.append([a, r >> 7, v, int(r == 0), c])\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('adc without carry', [17, 0, [['adc', 32], ['adc', 5]]], [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 145]]], [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 254]]], [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 126]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [127, 0, [['adc', 128], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [56, 1, [['adc', 255]]], [[56, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [81, 0, [['sbc', 16], ['sbc', 63]]], [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 62], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 193]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [18, 0, [['adc', 32], ['adc', 5]]], [[50, 0, 0, 0, 0], [55, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 146]]], [[160, 1, 1, 0, 0], [50, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 253]]], [[0, 0, 0, 1, 1], [254, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 125]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [242, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [126, 0, [['adc', 129], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [57, 1, [['adc', 255]]], [[57, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [82, 0, [['sbc', 16], ['sbc', 63]]], [[65, 0, 0, 0, 1], [2, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 61], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 194]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [19, 0, [['adc', 32], ['adc', 5]]], [[51, 0, 0, 0, 0], [56, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 147]]], [[160, 1, 1, 0, 0], [51, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 252]]], [[0, 0, 0, 1, 1], [253, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 124]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [243, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [125, 0, [['adc', 130], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [58, 1, [['adc', 255]]], [[58, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [83, 0, [['sbc', 16], ['sbc', 63]]], [[66, 0, 0, 0, 1], [3, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 60], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 195]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [20, 0, [['adc', 32], ['adc', 5]]], [[52, 0, 0, 0, 0], [57, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 148]]], [[160, 1, 1, 0, 0], [52, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 251]]], [[0, 0, 0, 1, 1], [252, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 123]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [244, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [124, 0, [['adc', 131], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [59, 1, [['adc', 255]]], [[59, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [84, 0, [['sbc', 16], ['sbc', 63]]], [[67, 0, 0, 0, 1], [4, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 59], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 196]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])], [('adc without carry', [21, 0, [['adc', 32], ['adc', 5]]], [[53, 0, 0, 0, 0], [58, 0, 0, 0, 0]]), ('adc signed overflow both ways', [80, 0, [['adc', 80], ['adc', 149]]], [[160, 1, 1, 0, 0], [53, 0, 1, 0, 1]]), ('adc carry out to zero', [255, 1, [['adc', 0], ['adc', 250]]], [[0, 0, 0, 1, 1], [251, 1, 0, 0, 0]]), ('sbc with carry set (no borrow)', [80, 1, [['sbc', 48], ['sbc', 176], ['sbc', 122]]], [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [245, 1, 0, 0, 0]]), ('sum of exactly 0xFF', [123, 0, [['adc', 132], ['adc', 0]]], [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]]), ('carry in wraps operand', [60, 1, [['adc', 255]]], [[60, 0, 0, 0, 1]]), ('sbc with carry clear (borrow)', [85, 0, [['sbc', 16], ['sbc', 63]]], [[68, 0, 0, 0, 1], [5, 0, 0, 0, 1]]), ('cmp orders and keeps accumulator', [64, 0, [['cmp', 64], ['cmp', 65], ['cmp', 58], ['adc', 1]]], [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]]), ('sbc to exactly zero', [33, 1, [['sbc', 33], ['cmp', 197]]], [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]])]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-instruction-set-emulation-adc-sbc-flags-carry-out-threshold","generated_at":"2026-09-29T14:51:16.612602+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"CPU emulators live or die on flag semantics; carry-as-inverted-borrow and overflow are the classic 8-bit emulation bugs.","repair":"Carry is set only when the 9-bit sum exceeds 0xFF.","root_cause":"The carry threshold is inclusive of 0xFF.","sha256":"2936f9e0dd1a621b60a60bfff688671fb5009b131bd26d6d52900011e83bba40","title":"Carry set on a sum of exactly 0xFF · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":39.253,"exit_code":1,"observations":[{"actual":[[49,0,0,0,0],[54,0,0,0,0]],"check":"adc without carry","expected":[[49,0,0,0,0],[54,0,0,0,0]],"passed":true},{"actual":[[160,1,1,0,0],[49,0,1,0,1]],"check":"adc signed overflow both ways","expected":[[160,1,1,0,0],[49,0,1,0,1]],"passed":true},{"actual":[[0,0,0,1,1],[255,1,0,0,0]],"check":"adc carry out to zero","expected":[[0,0,0,1,1],[255,1,0,0,0]],"passed":true},{"actual":[[32,0,0,0,1],[112,0,0,0,0],[241,1,0,0,0]],"check":"sbc with carry set (no borrow)","expected":[[32,0,0,0,1],[112,0,0,0,0],[241,1,0,0,0]],"passed":true},{"actual":[[255,1,0,0,0],[255,1,0,0,0]],"check":"sum of exactly 0xFF","expected":[[255,1,0,0,0],[255,1,0,0,0]],"passed":true},{"actual":[[56,0,0,0,0]],"check":"carry in wraps operand","expected":[[56,0,0,0,1]],"passed":false},{"actual":[[64,0,0,0,1],[1,0,0,0,1]],"check":"sbc with carry clear (borrow)","expected":[[64,0,0,0,1],[1,0,0,0,1]],"passed":true},{"actual":[[64,0,0,1,1],[64,1,0,0,0],[64,0,0,0,1],[66,0,0,0,0]],"check":"cmp orders and keeps accumulator","expected":[[64,0,0,1,1],[64,1,0,0,0],[64,0,0,0,1],[66,0,0,0,0]],"passed":true},{"actual":[[0,0,0,1,1],[0,0,0,0,0]],"check":"sbc to exactly zero","expected":[[0,0,0,1,1],[0,0,0,0,0]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"adc without carry\", \"actual\": [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]], \"expected\": [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]], \"passed\": true}, {\"check\": \"adc signed overflow both ways\", \"actual\": [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]], \"expected\": [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]], \"passed\": true}, {\"check\": \"adc carry out to zero\", \"actual\": [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]], \"expected\": [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"sbc with carry set (no borrow)\", \"actual\": [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]], \"expected\": [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"sum of exactly 0xFF\", \"actual\": [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]], \"expected\": [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"carry in wraps operand\", \"actual\": [[56, 0, 0, 0, 0]], \"expected\": [[56, 0, 0, 0, 1]], \"passed\": false}, {\"check\": \"sbc with carry clear (borrow)\", \"actual\": [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]], \"expected\": [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]], \"passed\": true}, {\"check\": \"cmp orders and keeps accumulator\", \"actual\": [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]], \"expected\": [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]], \"passed\": true}, {\"check\": \"sbc to exactly zero\", \"actual\": [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], \"expected\": [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":39.213,"exit_code":1,"observations":[{"actual":[[49,0,0,0,0],[54,0,0,0,0]],"check":"adc without carry","expected":[[49,0,0,0,0],[54,0,0,0,0]],"passed":true},{"actual":[[160,1,1,0,0],[49,0,1,0,1]],"check":"adc signed overflow both ways","expected":[[160,1,1,0,0],[49,0,1,0,1]],"passed":true},{"actual":[[0,0,0,1,1],[255,1,0,0,1]],"check":"adc carry out to zero","expected":[[0,0,0,1,1],[255,1,0,0,0]],"passed":false},{"actual":[[32,0,0,0,1],[112,0,0,0,0],[241,1,0,0,0]],"check":"sbc with carry set (no borrow)","expected":[[32,0,0,0,1],[112,0,0,0,0],[241,1,0,0,0]],"passed":true},{"actual":[[255,1,0,0,1],[0,0,0,1,1]],"check":"sum of exactly 0xFF","expected":[[255,1,0,0,0],[255,1,0,0,0]],"passed":false},{"actual":[[56,0,0,0,1]],"check":"carry in wraps operand","expected":[[56,0,0,0,1]],"passed":true},{"actual":[[64,0,0,0,1],[1,0,0,0,1]],"check":"sbc with carry clear (borrow)","expected":[[64,0,0,0,1],[1,0,0,0,1]],"passed":true},{"actual":[[64,0,0,1,1],[64,1,0,0,0],[64,0,0,0,1],[66,0,0,0,0]],"check":"cmp orders and keeps accumulator","expected":[[64,0,0,1,1],[64,1,0,0,0],[64,0,0,0,1],[66,0,0,0,0]],"passed":true},{"actual":[[0,0,0,1,1],[0,0,0,0,0]],"check":"sbc to exactly zero","expected":[[0,0,0,1,1],[0,0,0,0,0]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"adc without carry\", \"actual\": [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]], \"expected\": [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]], \"passed\": true}, {\"check\": \"adc signed overflow both ways\", \"actual\": [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]], \"expected\": [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]], \"passed\": true}, {\"check\": \"adc carry out to zero\", \"actual\": [[0, 0, 0, 1, 1], [255, 1, 0, 0, 1]], \"expected\": [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]], \"passed\": false}, {\"check\": \"sbc with carry set (no borrow)\", \"actual\": [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]], \"expected\": [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"sum of exactly 0xFF\", \"actual\": [[255, 1, 0, 0, 1], [0, 0, 0, 1, 1]], \"expected\": [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]], \"passed\": false}, {\"check\": \"carry in wraps operand\", \"actual\": [[56, 0, 0, 0, 1]], \"expected\": [[56, 0, 0, 0, 1]], \"passed\": true}, {\"check\": \"sbc with carry clear (borrow)\", \"actual\": [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]], \"expected\": [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]], \"passed\": true}, {\"check\": \"cmp orders and keeps accumulator\", \"actual\": [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]], \"expected\": [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]], \"passed\": true}, {\"check\": \"sbc to exactly zero\", \"actual\": [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], \"expected\": [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":38.351,"exit_code":0,"observations":[{"actual":[[49,0,0,0,0],[54,0,0,0,0]],"check":"adc without carry","expected":[[49,0,0,0,0],[54,0,0,0,0]],"passed":true},{"actual":[[160,1,1,0,0],[49,0,1,0,1]],"check":"adc signed overflow both ways","expected":[[160,1,1,0,0],[49,0,1,0,1]],"passed":true},{"actual":[[0,0,0,1,1],[255,1,0,0,0]],"check":"adc carry out to zero","expected":[[0,0,0,1,1],[255,1,0,0,0]],"passed":true},{"actual":[[32,0,0,0,1],[112,0,0,0,0],[241,1,0,0,0]],"check":"sbc with carry set (no borrow)","expected":[[32,0,0,0,1],[112,0,0,0,0],[241,1,0,0,0]],"passed":true},{"actual":[[255,1,0,0,0],[255,1,0,0,0]],"check":"sum of exactly 0xFF","expected":[[255,1,0,0,0],[255,1,0,0,0]],"passed":true},{"actual":[[56,0,0,0,1]],"check":"carry in wraps operand","expected":[[56,0,0,0,1]],"passed":true},{"actual":[[64,0,0,0,1],[1,0,0,0,1]],"check":"sbc with carry clear (borrow)","expected":[[64,0,0,0,1],[1,0,0,0,1]],"passed":true},{"actual":[[64,0,0,1,1],[64,1,0,0,0],[64,0,0,0,1],[66,0,0,0,0]],"check":"cmp orders and keeps accumulator","expected":[[64,0,0,1,1],[64,1,0,0,0],[64,0,0,0,1],[66,0,0,0,0]],"passed":true},{"actual":[[0,0,0,1,1],[0,0,0,0,0]],"check":"sbc to exactly zero","expected":[[0,0,0,1,1],[0,0,0,0,0]],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"adc without carry\", \"actual\": [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]], \"expected\": [[49, 0, 0, 0, 0], [54, 0, 0, 0, 0]], \"passed\": true}, {\"check\": \"adc signed overflow both ways\", \"actual\": [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]], \"expected\": [[160, 1, 1, 0, 0], [49, 0, 1, 0, 1]], \"passed\": true}, {\"check\": \"adc carry out to zero\", \"actual\": [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]], \"expected\": [[0, 0, 0, 1, 1], [255, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"sbc with carry set (no borrow)\", \"actual\": [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]], \"expected\": [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [241, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"sum of exactly 0xFF\", \"actual\": [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]], \"expected\": [[255, 1, 0, 0, 0], [255, 1, 0, 0, 0]], \"passed\": true}, {\"check\": \"carry in wraps operand\", \"actual\": [[56, 0, 0, 0, 1]], \"expected\": [[56, 0, 0, 0, 1]], \"passed\": true}, {\"check\": \"sbc with carry clear (borrow)\", \"actual\": [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]], \"expected\": [[64, 0, 0, 0, 1], [1, 0, 0, 0, 1]], \"passed\": true}, {\"check\": \"cmp orders and keeps accumulator\", \"actual\": [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]], \"expected\": [[64, 0, 0, 1, 1], [64, 1, 0, 0, 0], [64, 0, 0, 0, 1], [66, 0, 0, 0, 0]], \"passed\": true}, {\"check\": \"sbc to exactly zero\", \"actual\": [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], \"expected\": [[0, 0, 0, 1, 1], [0, 0, 0, 0, 0]], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}