Exercise 2: Which Chip's Carry Convention x86-64 Matches — Possible Solution ==================================================================== WHICH CONVENTION X86-64 MATCHES ------------------------------ Per this chapter's own "Resolving cpu8bit1-12's Cliffhanger" section, x86-64's CF convention after CMP/SUB matches the Z80's own convention — NOT the 6502's. The 6502's CMP used the opposite reading (Carry SET meant "no borrow needed," i.e. the first value was large enough); the Z80's CP and x86-64's CMP/SUB both use the same reading as each other. WHAT CF SET ACTUALLY MEANS IN X86-64 TERMS ------------------------------ Per this chapter's own statement, CF is set after a CMP or SUB when a BORROW was needed to compute the result — meaning the destination operand was smaller than the source operand (comparing as unsigned values). Concretely: for CMP RAX, RBX (computing RAX - RBX), CF becomes SET if RAX is smaller than RBX unsigned, and CF is CLEAR if RAX is greater than or equal to RBX unsigned — the identical reading cpu8bit1-12 established for the Z80's own CP instruction. WHY THIS MATTERS PRACTICALLY ------------------------------ Anyone whose intuition was shaped by the 6502's own inverted convention (Carry set = "big enough," per cpu8bit1-3) would read x86-64's CF backwards unless they specifically remember that x86-64 sides with the Z80's convention instead. This chapter's own resolution exists specifically to settle that ambiguity with a real, concrete third data point, rather than leaving the reader to guess which of the two prior conventions a brand new architecture happened to inherit. WHY THIS WORKS AS AN ANSWER ------------------------------ It states clearly and directly which of the two prior conventions x86-64 matches (the Z80's, not the 6502's), explains precisely what "CF set" means in terms of the actual comparison being performed, and notes the practical risk of misapplying the wrong prior intuition.