FAILURE MAP
← Case archive

FA-89662 / Instruction set emulation / Member archive

SUB half borrow set on equal nibbles · case 02

Subtracting a value with the same low nibble sets H.

Member previewVariant 2 · 3 implementations · 9 checks per implementation

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 fixture

This sample comes from the broken implementation of a controlled reproducer.

Boundary fixtureActualExpectedOutcome
sub half borrow[[32, 0, 0, 1, 0, 1, 0], [27, 0, 0, 1, 0, 1, 0], [12, 0, 0, 1, 0, 1, 0]][[32, 0, 0, 0, 0, 1, 0], [27, 0, 0, 1, 0, 1, 0], [12, 0, 0, 1, 0, 1, 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 ↗