Branch instructions result in infinite loop?
Page 2 of 2

Author:  tokumaru [ Sat May 13, 2017 1:04 pm ]
Post subject:  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.

Author:  rainwarrior [ Sat May 13, 2017 11:37 pm ]
Post subject:  Re: Branch instructions result in infinite loop?

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?

Page 2 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group