- Is my understanding of how the 6502 handles inequalities correct?
- Am I correct in understanding there is no bitwise NOT instruction? If so, what's the best way to simulate ~ .A?
- How does the V flag fit into the inequality matrix? I get that it's out-of-range for 2's compliment in a single byte.
- How does BCD mode affect any of this?
So, I'm still tying to understand a few basic things about how the 6502 checks for inequality and one logic question. In the abstract I "get" that from the Negative, Zero, and Cary flags — 2^3=8 possible combinations of bits — logical inequalities emerge. What is less clear is what combination of flags constitute which specific inequalities. I had to consult 2-3 different documents in order to pull together this chart.
Even then, I may well have made mistakes. This is part of a journey on my part to better grasp the Processor Status Register's effects on the system as a whole. I was encouraged to dig along these lines due to a comment on another thread of mine.
It seems six possibilities should exist and that .P NZC drive the show:
Binary Inequality Chart
Code: Select all
Accumulator .P[NZC]
.A < M 100
.A > M 001
.A ≠ M 101
.A = M 010
.A ≤ M 110
.A ≥ M 011
.A ? M 000 (unsigned !=?)
.A ? M 111 (signed ==?)
Bruce Clark's article Compare Instructions an Branching helped. The Compare and Beyond article was instrumental. Without it, would not have the 3-bit logical pattern worked out the way that I did.
Jump Instructions: Unsigned Bytes
- BCC (Branch on Cary Clear) IF unsigned .A is < M .PC will branch to target.
- BCC (Branch on Cary Clear) IF unsigned .A is ≤ M .PC will branch to target.
- BCS (Branch on Cary Set) IF unsigned .A is > M .PC will branch to target.
- BCS (Branch on Cary Set) IF unsigned .A is ≥ M .PC will branch to target.
- BEQ (Branch if Equal to Zero Flag Set) IF unsigned .A is ≤ M .PC will branch to target.
- BEQ (Branch if Equal to Zero Flag Set) IF unsigned .A is = M .PC will branch to target.
- BEQ (Branch if Equal to Zero Flag Set) IF unsigned .A is > M .PC will NOT branch to target.
- BVC (BVCBranch if oVerflow Clear) IF unsigned .A is ? .PC will do what?
- BMI (Branch if Minus [negative] flag Set) IF signed .A is < M .PC will branch to target.
- BEQ (Branch if Equal to Zero Flag Set) IF signed .A is = M .PC will branch to target.
- BEQ (Branch if Equal to Zero Flag Set) IF signed .A is > M .PC will NOT branch to target.
- BPL (Branch if Minus [negative] flag clear) IF signed .A is > M .PC will branch to target.
- BMI (Branch if Minus [negative] flag set) IF signed .A is ≤ M .PC will branch to target.
- BEQ (Branch if Equal to Zero Flag Set) IF signed .A is ≤ M .PC will branch to target.
- BPL (Branch if Minus [negative] flag clear) IF signed .A is ≥ M .PC will branch to target.
- BVC (BVCBranch if oVerflow Clear) IF signed .A is ? .PC will do what?
Bitwise Logic
From the 6502 instruction set, I see most of what I expect for bitwise operations:
- The and instruction is bitwise AND (&) .A which interacts with .P: N+, Z+.
- The ora instruction is bitwise OR (|) .A which interacts with .P: N+, Z+.
- The eor instruction is bitwise XOR (^) .A which interacts with .P: N+, Z+.
- I'm not sure, but it seems bitwise NOT (~) .A does not exist?!
- The asl instruction is arithmetic shift left (<<) .A which interacts with .P: N+, Z+, C+.
- The lsr instruction is arithmetic shift right (>>) .A which interacts with .P: N-, Z+.