This information is coming from an embedding programming tutorial from YOUTUBE.
The instructor recommends to assign a value to a certain memory location by using an OR operation.
SYSCTL_RCGCGPIO_R |= (1U<<5);
My question is why not just,
SYSCTL_RCGCGPIO_R = (1U<<5);
The definition of SYSCTL_RCGCGPIO_R is
#define SYSCTL_RCGCGPIO_R (*((volatile unsigned long *)0x400FE608))
Given that the value at the memory location of SYSCTL_RCGCGPIO_R is 0, I understand that both assignments are equal.
But wouldn't first assignment cause unnecessary bit operation?
Is there a special reason for utilizing OR bitwise operation when writing a value to specific memory location?
The reason why the tutorial suggests that you use an OR instruction instead of a direct assignment is because the target value may be different from zero due to circumstances that are beyond your control, and you do not want to modify any bits other than bit 6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With