Set a bit, clear a bit.
Moderator: Moderators
Set a bit, clear a bit.
While reading multiple sources, I often find the terms "setting / clearing" a bit.
Now, I am not a native speaker, plus my experience with low-level programming is zero.
We also say "the devil is in the detail", therefore...I honestly prefer to ask
I think that:
- set a bit = put its value to 1
- clear a bit = put its value to 0
May I ask if I understood correctly? Thanks in advance.
Now, I am not a native speaker, plus my experience with low-level programming is zero.
We also say "the devil is in the detail", therefore...I honestly prefer to ask
I think that:
- set a bit = put its value to 1
- clear a bit = put its value to 0
May I ask if I understood correctly? Thanks in advance.
Re: Set a bit, clear a bit.
That's correct.
Re: Set a bit, clear a bit.
The original question has been answered, but as a tip, the following instructions are used for these operations:
ORA - set bits of A that are '1' in the operand
AND - clear bits of A that are '0' in the operand
EOR - flip bits of A that are '1' in the operand
For example if I had a variable that holds bit flags and I wanted to set only the highest two bits, I can do this:
ORA - set bits of A that are '1' in the operand
AND - clear bits of A that are '0' in the operand
EOR - flip bits of A that are '1' in the operand
For example if I had a variable that holds bit flags and I wanted to set only the highest two bits, I can do this:
Code: Select all
lda variable
ora #%11000000
sta variable
Re: Set a bit, clear a bit.
Also "reset" is a synonym to "clear" when it comes to bit manipulation.
Re: Set a bit, clear a bit.
Thank you, that's helpful to know!
-
- Posts: 1318
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: Set a bit, clear a bit.
OR can be represented by + or |
1 + 1 = 1
1 + 0 = 1
0 + 1 = 1
0 + 0 = 0
AND can be represented by * or &
1 * 1 = 1
1 * 0 = 0
0 * 1 = 0
0 * 0 = 0
XOR (used in the EOR instruction on the NES)
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0
Often I find starting at the foundation of an idea much simpler than trying to learn from a summary.
edit: the ORA instruction, on the NES, performs an OR between each pair of bits... i.e. bit0 in the accumulator and bit0 in the value supplied to the instruction; same with each other bit pair: bit1 OR through bit7 OR; the result of those 8 ORs is stored in the accumulator (the bit0 OR winds up in bit0... etc.).
Same concept for the NES’ AND and EOR instructions.
1 + 1 = 1
1 + 0 = 1
0 + 1 = 1
0 + 0 = 0
AND can be represented by * or &
1 * 1 = 1
1 * 0 = 0
0 * 1 = 0
0 * 0 = 0
XOR (used in the EOR instruction on the NES)
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0
Often I find starting at the foundation of an idea much simpler than trying to learn from a summary.
edit: the ORA instruction, on the NES, performs an OR between each pair of bits... i.e. bit0 in the accumulator and bit0 in the value supplied to the instruction; same with each other bit pair: bit1 OR through bit7 OR; the result of those 8 ORs is stored in the accumulator (the bit0 OR winds up in bit0... etc.).
Same concept for the NES’ AND and EOR instructions.
Re: Set a bit, clear a bit.
Hello. Well, my initial confusion was actually just a linguistic one, but always good to have some tricks more
-
- Posts: 1318
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: Set a bit, clear a bit.
Hi ludoVIC. I do understand the thread problem had already been solved, but za909’s odd post influenced me to reply... I’m sorry for making this thread long. At the same time I’m pleased you seem to appreciate my post.
Re: Set a bit, clear a bit.
Hi, no worries at all. You're welcome; I think it's good to share ideas capable of helping a potential future reader
Thanks for the feedback and see you around here!
Thanks for the feedback and see you around here!
-
- Posts: 1318
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas