Many (PIC)chips support the COMF instruction, but it does not seem to be supported in GCBasic.
I have been using XOR (to obtain the complement of variable1 and put it in variable2).
variable2=255 XOR variable1
This is 3 instructions in ASM
COMF variable1,W
MOVWF variable2
achieves the same with 2 instructions.
This may not seem like much but I am using it to drive an LCD display with the processor running at 32kHz (LCDs need to reverse the polarity regularly).
Anyway such is the versatility of GCBasic that you can throw in ASM lines and they will compile (and work).
I'm not really sure why chips with limited instruction sets include the COMF instruction (as there is an easy workaround).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am easily baffled by boolean logic at the best of times, but doesn't "NOT" achieve the same thing as:
variable2=255XORvariable1
as in:
Variable2=NOTvariable1
I understand that COMF gives a complementary inversion which should maintain the two's complement value, but would (or does) XOR'ing with 255 keep the signed 'bit'?
I've never needed to work with signed integers so perhaps that is where my lack of understanding lies.
I always keep well away from these type of instructions, due to my massive ignorance of them (as shown) so I would be tempted just to use "NOT" having checked first if the value was greater than 127 were I interested in the signed aspect.
Sorry for being dense. Any explanations may help me understand things a little better.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You're quite correct. It was me being dense, never having used NOT I did not know of its existence.
And if you try...
variable2= NOT variable1
it gives the expected ASM
COMF variable1,W
MOVWF variable2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In my defense there is no mention of AND OR XOR NOT in "bit-wise operations" in the help file.
They only mention in "variable operations" in one sentence And, Or, Xor and Not operators function both as bitwise and logical operators.
Almost all of that section deals with their use as Boolean operators.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you have an idea of how best to word it so that others don't get caught out by that?
Updating help to ensure that others don't get misled as you did is one of the most valuable contributions to GCBASIC that any community member can make.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Chris from all those who may be misled.
It is good that the help is kept as helpful as possible as I'm sure that is where newcomers are either lost or pulled into the GCB community.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many (PIC)chips support the COMF instruction, but it does not seem to be supported in GCBasic.
I have been using XOR (to obtain the complement of variable1 and put it in variable2).
variable2=255 XOR variable1
This is 3 instructions in ASM
COMF variable1,W
MOVWF variable2
achieves the same with 2 instructions.
This may not seem like much but I am using it to drive an LCD display with the processor running at 32kHz (LCDs need to reverse the polarity regularly).
Anyway such is the versatility of GCBasic that you can throw in ASM lines and they will compile (and work).
I'm not really sure why chips with limited instruction sets include the COMF instruction (as there is an easy workaround).
I am easily baffled by boolean logic at the best of times, but doesn't "NOT" achieve the same thing as:
as in:
I understand that COMF gives a complementary inversion which should maintain the two's complement value, but would (or does) XOR'ing with 255 keep the signed 'bit'?
I've never needed to work with signed integers so perhaps that is where my lack of understanding lies.
I always keep well away from these type of instructions, due to my massive ignorance of them (as shown) so I would be tempted just to use "NOT" having checked first if the value was greater than 127 were I interested in the signed aspect.
Sorry for being dense. Any explanations may help me understand things a little better.
You're quite correct. It was me being dense, never having used NOT I did not know of its existence.
And if you try...
variable2= NOT variable1
it gives the expected ASM
COMF variable1,W
MOVWF variable2
Sorry, I didn't mean to suggest anything other than my befuddlement!
you could say how nice it looked
In my defense there is no mention of AND OR XOR NOT in "bit-wise operations" in the help file.
They only mention in "variable operations" in one sentence And, Or, Xor and Not operators function both as bitwise and logical operators.
Almost all of that section deals with their use as Boolean operators.
Valid observation and a good point Dave.
Do you have an idea of how best to word it so that others don't get caught out by that?
Updating help to ensure that others don't get misled as you did is one of the most valuable contributions to GCBASIC that any community member can make.
Thanks Chris from all those who may be misled.
It is good that the help is kept as helpful as possible as I'm sure that is where newcomers are either lost or pulled into the GCB community.