FA-89660 / Instruction set emulation / Member archive
DEC half borrow uses the increment rule · case 05
Decrementing 0x10 leaves H clear.
Case contract
Input [a, ops]; ops are 'inc', 'dec', ['add', v], ['sub', v] on 8-bit A; carry starts 0. After each op report [A, S, Z, H, PV, N, C]. inc: H = carry out of bit 3, PV = (A was 0x7F), N = 0, C unchanged. dec: H = borrow from bit 4 (low nibble was 0), PV = (A was 0x80), N = 1, C unchanged. add: H = carry out of bit 3, PV = signed overflow, N = 0, C = carry out. sub: H = borrow into bit 4 (low nibble of A < low nibble of v), PV = signed overflow, N = 1, C = borrow.
Why this case matters
Half-carry and parity/overflow flags are observable through DAA and conditional branches; emulators often get the INC/DEC special cases wrong.
One recorded failure
Sample boundary fixtureThis sample comes from the broken implementation of a controlled reproducer.
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| inc wraps to zero keeps carry | [[16, 0, 0, 0, 0, 0, 1], [17, 0, 0, 0, 0, 0, 1], [16, 0, 0, 0, 0, 1, 1], [15, 0, 0, 0, 0, 1, 1], [14, 0, 0, 1, 0, 1, 1], [13, 0, 0, 0, 0, 1, 1], [12, 0, 0, 0, 0, 1, 1]] | [[16, 0, 0, 0, 0, 0, 1], [17, 0, 0, 0, 0, 0, 1], [16, 0, 0, 0, 0, 1, 1], [15, 0, 0, 1, 0, 1, 1], [14, 0, 0, 0, 0, 1, 1], [13, 0, 0, 0, 0, 1, 1], [12, 0, 0, 0, 0, 1, 1]] | 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 ↗