Branch instructions result in infinite loop?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Branch instructions result in infinite loop?

Post by tokumaru »

Signed or unsigned is the same when represented in binary. The program gets to choose whether to interpret them as signed or unsigned.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Branch instructions result in infinite loop?

Post by rainwarrior »

PolarBITS wrote:
rainwarrior wrote:(On the first test it will be $FF = -1, on the 256th test it will be back down to 0.)
So you're saying that all numbers in RAM are unsigned bytes? I completely forgot about that lol.
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.

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?
Post Reply