5.13 __lac Intrinsic Function

The IAR __lac intrinsic function provides access to the lac instruction, available on AVRxm devices. The lac (Load And Clear) instruction loads the memory contents at the address held by the Z register into the Rd register specified while simultaneously clearing those bits at that same address held by the Z register that were set in the Rd register.

Suggested Replacement

There is no MPLAB XC8 equivalent built-in function; however, the instruction can be inserted explicitly using in-line assembly code.

Use in-line assembly to directly write an lac instruction.

Caveats

None

Examples

Consider migrating IAR code such as:

unsigned char loadAndClear(unsigned char regD, unsigned char * Zptr) {
    unsigned char cleared = __lac(regD, Zptr);
    return cleared;
}
to MPLAB XC8 code similar to:
#include <xc.h>

unsigned char lac(unsigned char v, unsigned char * addr) {
        __asm__("movw r30, %[ADDR] \n\t"
                "lac Z, %[Rd] \n\t"
                : [Rd] "+r" (v), "+m" (*addr)
                : [ADDR] "r" ((unsigned int)addr)
                : "r30", "r31");
        return v;
}

unsigned char loadAndClear(unsigned char regD, unsigned char * Zptr) {
    unsigned char cleared = lac(regD, Zptr);
    return cleared;
}

Further Information

See the In-line Assembly section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on adding in-line assembly.