Branch instructions result in infinite loop?
Moderator: Moderators
Re: Branch instructions result in infinite loop?
Signed or unsigned is the same when represented in binary. The program gets to choose whether to interpret them as signed or unsigned.
- rainwarrior
- Posts: 8062
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Branch instructions result in infinite loop?
Well, I was really saying that $FF and -1 are equivalent names for binary %11111111. It's a standard two's complement binary representation of numbers.PolarBITS wrote:So you're saying that all numbers in RAM are unsigned bytes? I completely forgot about that lol.rainwarrior wrote:(On the first test it will be $FF = -1, on the 256th test it will be back down to 0.)
Aside from the indexed address modes where X or Y is always interpreted as unsigned, or the immediate branch argument which is always signed, it's generally up to how you use it. Usually "unsigned" usage is simpler/faster, so it's sort of the default case for 6502.
For instance: an unsigned less-than comparison is just CMP followed by BCC or BCS. The equivalent signed less-than comparison involves a few more steps, though if the numbers involved are small enough not to cause an overflow, CMP followed by BMI or BPL can be sufficient as a limited "signed" comparison. BMI might also be useful for testing an unsigned byte for >= 128, so it's not necessarily a "signed" instruction.
Anyhow, it may be helpful when learning to think of it as unsigned by default?