From fe90271558c9a373ba781ae4a38b662365e7b3bd Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 12 Jul 2020 14:09:33 +0200 Subject: [PATCH] Fix the carry flag value for the CMP, CPX and CPY 6502 instructions The CPU manual states "the carry flag is set when the value in memory is less than or equal to the accumulator, reset when it is greater than the accumulator". --- Ghidra/Processors/6502/data/languages/6502.slaspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Ghidra/Processors/6502/data/languages/6502.slaspec b/Ghidra/Processors/6502/data/languages/6502.slaspec index 83af9267bc..7775ef3f0d 100644 --- a/Ghidra/Processors/6502/data/languages/6502.slaspec +++ b/Ghidra/Processors/6502/data/languages/6502.slaspec @@ -233,7 +233,7 @@ ADDRI: imm16 is imm16 { tmp:2 = imm16; export *:2 tmp; } local op1 = OP1; local tmp = A - op1; resultFlags(tmp); - C = (A < op1); + C = (A >= op1); } :CPX OP2 is (op=0xE0 | op=0xE4 | op=0xEC) ... & OP2 @@ -241,7 +241,7 @@ ADDRI: imm16 is imm16 { tmp:2 = imm16; export *:2 tmp; } local op1 = OP2; local tmp = X - op1; resultFlags(tmp); - C = (A < op1); + C = (X >= op1); } :CPY OP2 is (op=0xC0 | op=0xC4 | op=0xCC) ... & OP2 @@ -249,7 +249,7 @@ ADDRI: imm16 is imm16 { tmp:2 = imm16; export *:2 tmp; } local op1 = OP2; local tmp = Y - op1; resultFlags(tmp); - C = (A < op1); + C = (Y >= op1); } :DEC OP2 is (op=0xC6 | op=0xCE | op=0xD6 | op=0xDE) ... & OP2