FA-89344 / Instruction set emulation / Member archive
SBC treats the carry flag as a borrow flag · case 04
Subtraction with carry set comes out one too small and with carry clear one too large.
Case 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.
Why this case matters
CPU emulators live or die on flag semantics; carry-as-inverted-borrow and overflow are the classic 8-bit emulation bugs.
One recorded failure
Sample boundary fixtureThis sample comes from the broken implementation of a controlled reproducer.
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| sbc with carry set (no borrow) | [[31, 0, 0, 0, 1], [110, 0, 0, 0, 0], [243, 1, 0, 0, 0]] | [[32, 0, 0, 0, 1], [112, 0, 0, 0, 0], [244, 1, 0, 0, 0]] | Failed |
MEMBER ARCHIVE
The complete case is available to members.
This record includes three runnable implementations, regression fixtures, execution results, and source hashes.
Member access is invitation-based. Sign in with your invited account to inspect the sources.
Sign in to the archive ↗