Jump to content
IGNORED

ROR/ROL question


Ze_ro

Recommended Posts

Okay, after pouring over 6502 information, there's one thing that still bothers me, and it has to do with the ROR and ROL instructions. Lets say I have 1 in the carry bit, and the accumulator is 01010110. If I then do a ROL, do I get 10101101 (with a carry of 0), or do I get 10101100 (with a carry of 0).

 

Basically, every explanation I've seen claims that bit 7 is shifted into the carry, and the carry is shifted into bit 0... but I'm not sure what order it uses. I would assume it would shift 7->C first, and then C->0, otherwise ROL wouldn't be useful enough to differentiate it from ASL in my opinion.

Link to comment
Share on other sites

  • 3 weeks later...

In an effort to keep the number of posts down here, I want to just add my newest question to this post. It involves bit manipulation, similar in a sence.

 

Could somebody explain or point me to a description of the 6502 uses of AND, XOR, EOR, etc and exactly how they work?

 

For example if I want to change the right 2 bits of any of these bytes:

(10101010 or 10011010 or 10001010 etc..)

so that the right 2 bits are 1's, I suspect I can use one of those masking statements so that it would change either a 0 or a 1 in a bit to a 1 everytime.

 

Something like this:

 

lda %10101010

AND %00000011 would that work?

 

(or)

lda %10101010

XOR %00000011 how bout this?

 

(or)

lda %10101010

EOR %00000011 which one will work?

 

Again, my goal is to change those 2 right bits to 1's regardless of what the actual value is. I hope this makes sense!

Link to comment
Share on other sites

You have that kinda backwards...AND will set the bit only if the same bit is set in both arguments. This is a handy way to strip bits off a value. If you only want the lower nybble, you would AND #$0F (since the upper four bits are zero in the argument, they will be stripped from the accumulator).

 

EOR is also incorrect, this instruction will flip the bits that are mentioned in the argument...1010 EOR 1100 would become 0110.

 

XOR is not part of the 6502 instruction set. This will set a bit to zero if they are the same in both arguments...1010 XOR 1100 would become 0110 (notice how the first bit changes).

 

What you are after is ORA...this will set the bit if either bit is set in the arguments (1010 ORA 1100 would become 1110). The instruction you are after is ORA #$03.

 

[ 10-09-2001: Message edited by: Nukey Shay ]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...