Ze_ro Posted September 22, 2001 Share Posted September 22, 2001 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. Quote Link to comment Share on other sites More sharing options...
DEBRO Posted September 22, 2001 Share Posted September 22, 2001 Think of ROL and ROR as a rotating wheel. So using your example you would get 10101101 (with a carry of 0). Using ASL the bits are shifted to the left but the carry bit is not shifted to your low bit. Quote Link to comment Share on other sites More sharing options...
+Cafeman Posted October 9, 2001 Share Posted October 9, 2001 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! Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted October 9, 2001 Share Posted October 9, 2001 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 ] Quote Link to comment Share on other sites More sharing options...
+Cafeman Posted October 9, 2001 Share Posted October 9, 2001 ORA it is then! Thanks... I'm using this routine to change bg graphics pixel by pixel -- there are 4 pixels in a byte of screen memory so I must use ORA and a mask. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.