6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu May 09, 2024 3:13 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: 2's Complement or not?
PostPosted: Thu Sep 11, 2003 5:58 am 
Offline

Joined: Thu Sep 11, 2003 5:47 am
Posts: 45
11) Relative
This mode is used with Branch-on-Condition instructions. It is probably
the mode you will use most often. A 1 byte value is added to the program
counter, and the program continues execution from that address. The 1
byte number is treated as a signed number - i.e. if bit 7 is 1, the number
given byt bits 0-6 is negative; if bit 7 is 0, the number is positive. This
enables a branch displacement of up to 127 bytes in either direction.
eg bit no. 7 6 5 4 3 2 1 0 signed value unsigned value
value 1 0 1 0 0 1 1 1 -39 $A7
value 0 0 1 0 0 1 1 1 +39 $27

I took this from a reference document, but I wanted to check whether it was correct.

I was under the impression that the 6502 used 2's complement numbers, even in branches.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 11, 2003 8:02 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
Branch instruction operands are still twos' complements. BRA 00 (Branch Relative Always) or any of the other relative-branch instructions with a 00 operand basically amount to a two-byte no-op since you're saying, "Don't do anything to the program counter. Just let it continue on to the next instruction as normal." BRA $FE (80 FE) would repeat itself indefinitely. The branch range is 128 bytes back (with an operand of $80) to 127 bytes forward (with an operand of $7F), with the first byte of the next instrucion being considered 0, and the operand byte of the branch instruction itself being considered $FF.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


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

Search for:
Jump to: