Pregunta

Could anyone expain to me how does the bitwise AND operations work? I have following code:

CLRF LATC & 0x7F
MOVWF LATC & 0x7F

What is the purpose of using & 0x7F? What does that change?

Update: I know how general bitwise operations works, and I know that "CLRF LATC" should zero LATC register. But what does "CLRF LATC & 0x7F" to LATC register? Zeroes all but last bit?

¿Fue útil?

Solución

The operation is already performed by the assembler so "MOVWF 0x193 & 0x7F" (for example) is the same as "MOVWF 0x13" (because 0x193 & 0x7F = 0x13).

The reason to do this is the following one:

For larger PICs the memory is banked.

To write to Address 0x193 you'll have to switch to bank #3 (addresses 0x180-0x1FF) and write to address 0x13 (not to address 0x193).

This "bank-relative" address is calculated by AND-ing the absolute address and the number 0x7F.

Because symbols like "LATC" may be defined as absolute addresses (0x193) instead of relative addresses (0x13) you need this form of an instruction.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top