CMP Instruction
Posted: Thu Jun 03, 2004 5:02 pm
Hi,
I've been reading up on the CMP instruction (CMP and SBC are the only two that are giving me any grief) and I found some really good information on this web site, and I was doing well until a question poped into my head.
It says on tutorials/compare_beyond.html that "both [CMP and SBC] affect the N, Z, and C flags in exactly the same way".
Given this information I took the source code for my emulated SBC instruction and poped into my CMP instruction (ignoring the carry, not modifying the registers, and ignoring the BCD handling) and the results are NOT the same. Obviously something is wrong.
However, if I take the table (showing how the flags are set) listed on tutorials/compare_instructions.html and implement that in my CMP instruction and not do any subtracting etc. the instruction works perfect.
Am I missing something?
Any clarification on these two instructions would make me so happy...
Thanks,
Andrew
I've been reading up on the CMP instruction (CMP and SBC are the only two that are giving me any grief) and I found some really good information on this web site, and I was doing well until a question poped into my head.
It says on tutorials/compare_beyond.html that "both [CMP and SBC] affect the N, Z, and C flags in exactly the same way".
Given this information I took the source code for my emulated SBC instruction and poped into my CMP instruction (ignoring the carry, not modifying the registers, and ignoring the BCD handling) and the results are NOT the same. Obviously something is wrong.
However, if I take the table (showing how the flags are set) listed on tutorials/compare_instructions.html and implement that in my CMP instruction and not do any subtracting etc. the instruction works perfect.
Am I missing something?
Any clarification on these two instructions would make me so happy...
Thanks,
Andrew