I am excited to announce that the latest compiler update now supports two new compound operators: XOR= and OR=. These join our existing compound operators (++, --, +=, -=) to provide more efficient bit manipulation capabilities.
New Operators and Their Equivalents
XOR= Operator
The new compound XOR operator simplifies your code. These two code blocks do exactly the same thing:
; Using new XOR= operator
myVar XOR= 0b00001111
; Equivalent traditional code
myVar = myVar XOR 0b00001111
Here's a real-world example showing both forms:
; Toggle an LED using XOR=
PORTB.0 XOR= 1 'Toggles bit 0 of PORTB
; Same operation written longhand
PORTB.0 = PORTB.0 XOR 1
OR= Operator
portStatusOR=0b10000000'Sets bit 7 while preserving other bitsflagsOR=STATUS'Combines status bits with existing flags
Practical Applications
XOR= Use Cases:
Toggle bits without affecting others - perfect for flipping specific LED states or inverting signal lines
Implement simple encryption - XOR with a key pattern for basic data scrambling
Swap values without temporary storage:
; Using XOR=
a XOR= b
b XOR= a
a XOR= b 'Values are now swapped!
; Equivalent code without XOR=
a = a XOR b
b = b XOR a
a = a XOR b
OR= Use Cases:
Set specific bits while preserving others - ideal for configuring port settings
Combine status flags from different operations
Enable features without disrupting existing settings
Example: Shift Register Control
Here's how these operators simplify shift register handling:
#defineLATCH_PINPORTC.0#defineDATA_PINPORTC.1#defineCLOCK_PINPORTC.2SubUpdateDisplay(indisplayPatternasByte);ClearlatchPORTC=PORTCANDNOT(1<<LATCH_PIN);Shiftout8bitsDimbitcountasByteForbitCount=0to7;CleardatapinPORTC=PORTCANDNOT(1<<DATA_PIN);SetdatabitifneededIfdisplayPattern.7ThenPORTCOR=(1<<DATA_PIN)'Set only DATA_PIN End If ; Toggle clock using XOR= PORTC XOR= (1 << CLOCK_PIN) 'ToggleCLOCK_PIN;SametogglewithoutXOR=wouldbe:'PORTC=PORTCXOR(1<<CLOCK_PIN)displayPattern=displayPattern<<1Next;SetlatchtoupdatedisplayPORTCOR=(1<<LATCH_PIN)EndSub
Bit Manipulation Examples
Here's a practical example showing how XOR= can simplify LED patterns:
; Flash alternate LEDs on PORTBSubFlashLEDs; Toggle bits 0,2,4,6PORTBXOR=0b01010101; Equivalent without XOR='PORTB = PORTB XOR 0b01010101 ; Toggle bits 1,3,5,7 on next pass PORTB XOR= 0b10101010 ; Equivalent without XOR='PORTB = PORTB XOR 0b10101010End Sub
Compatibility
These new operators are available in the latest compiler version. All existing code using the traditional compound operators (++, --, +=, -=) continues to work as before.
Give these new operators a try and let me know how they improve your code! As always, I appreciate your feedback and suggestions for future enhancements.
Enjoy
Evan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
New Compound Operators in GCBASIC: XOR= and OR=
Hello GCBASIC community!
I am excited to announce that the latest compiler update now supports two new compound operators:
XOR=
andOR=
. These join our existing compound operators (++
,--
,+=
,-=
) to provide more efficient bit manipulation capabilities.New Operators and Their Equivalents
XOR= Operator
The new compound XOR operator simplifies your code. These two code blocks do exactly the same thing:
Here's a real-world example showing both forms:
OR= Operator
Practical Applications
XOR= Use Cases:
OR= Use Cases:
Example: Shift Register Control
Here's how these operators simplify shift register handling:
Bit Manipulation Examples
Here's a practical example showing how XOR= can simplify LED patterns:
Compatibility
These new operators are available in the latest compiler version. All existing code using the traditional compound operators (
++
,--
,+=
,-=
) continues to work as before.Give these new operators a try and let me know how they improve your code! As always, I appreciate your feedback and suggestions for future enhancements.
Enjoy
Evan
remember ssd1309 oscilloscope xor mode to erase graphics by redrawing them?
Yes, I still use it! And, the sprite demo!