3 ms·
Technically, the second block of code is not 100% equivalent. Why? Well, it uses more instructions (so more memory and also takes longer to execute) but
by indigo945 6y ago
Technically, the second block of code is not 100% equivalent.
Why? Well, it uses more instructions (so more memory and
also takes longer to execute) but it also sets ALL bits of
the Program Counter, not just the ones that a goto or call
can.
We could use the second block of code to goto to a correct
page, but it would be annoying to use in practice because it
would mangle the W register.
Does the code even work at all? I don't know anything about PIC microcontrollers, but I would have expected that writing to PCLACH would cause a jump immediately, meaning that the write to the low bits in PCL would never even happen.
- grantla 6y agoPCLATH is not actually the program counter; the real PC is only updated at GOTO/CALL time, and then PCLATH will be copied over.
- roamingryan 6y agoPCLATH stands for Program Counter LATch High (byte). In this case latch refers to the digital design technique where you have a register that holds bit(s) until some other event happens. The event in this case is a write to PCL. Once the event occurs, PCLATH is transferred to PCH synchronously/atomically with the write to PCL.
- Jetroid 6y agoWe can write to PCLATH without causing a jump. PCLATH is only read when we goto somewhere, or call a routine, or write to PCL.