6502 flag manipulation ====================== The Carry flag can be set cleared with SEC and CLC, but the other flags have no instructions to do so. oVerflow flag ------------- The 6502 has a CLV instruction to clear the oVerflow flag, but has no complementary SEV instruction to set the V flag. However, with careful arranging of code, you can do this by testing a byte of the code. For example: BIT setv ; V set from b6 of RTS opcode (also clears M) .setv RTS ; opcode is %01100000 BIT setv ; V set from b6 of JMP opcode (also clears M) .setv JMP dest ; opcode is %01001100 BIT setv ; V set from b6 of JMP opcode (also clears M) .setv JMP (vect) ; opcode is %01101100 BIT setv ; V set from b6 of NOP opcode (also sets M) .setv NOP ; opcode is %11001010 .bit LDA &FE08 ; where absaddr>=&C000 BIT bit+2 ; V set from b14 of &FE08 (also sets M) .bit LDA &FD ; where zpaddr>=&C0 BIT bit+1 ; V set from b6 of &FD (also sets M) Minus flag ---------- .bit LDA &FE08 ; where absaddr>=&8000 BIT bit+2 ; sets M from bit 15 &FE08 .bit LDA &FD ; where zpaddr>=&80 BIT bit+1 ; sets M from bit 7 of &FD ORA #&80 ; sets M, changing A LDr #num ; if num>&7F, sets M changing register .clrm BIT clrm ; opcode is %00101100, clears M AND #&7F ; clears M, changing A LDr #num ; if num<&80, clears M changing register Zero flag --------- CMP #num ; if num known to be same as A, will set Z CMP #num ; if num known to be different from A, will clear Z LDr #0 ; sets Z, also clearing register Complement Carry ---------------- PHP:PLA:EOR #&01:PHA:PLP ROL A:EOR #&01:ROR A ; also modifies M and Z ROR A:EOR #&80:ROL A ; also modifies M and Z