It is currently Sun Jan 20, 2019 1:57 pm

 All times are UTC - 7 hours

 Page 2 of 2 [ 17 posts ] Go to page Previous  1, 2
 Print view Previous topic | Next topic
Author Message
 Post subject: Re: Branch instructions result in infinite loop?Posted: Sat May 13, 2017 1:04 pm

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11094
Location: Rio de Janeiro - Brazil
Signed or unsigned is the same when represented in binary. The program gets to choose whether to interpret them as signed or unsigned.

Top

 Post subject: Re: Branch instructions result in infinite loop?Posted: Sat May 13, 2017 11:37 pm

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7111
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?

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 2 of 2 [ 17 posts ] Go to page Previous  1, 2

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: Google [Bot] and 5 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki