Playing with Arduino
A page to record my playing with Arduino
__LPM_enhanced__()

Abstract

assembler code that reads a byte of data stored in a specified address(PROGMEM area).

Source Code

The _LPM_enhanced_() is defined in hardware/tools/avr/avr/include/avr/pgmspace.h as below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#define __LPM_enhanced__(addr)  \
(__extension__({                \
    uint16_t __addr16 = (uint16_t)(addr); \
    uint8_t __result;           \
    __asm__ __volatile__        \
    (                           \
        "lpm %0, Z" "\n\t"      \
        : "=r" (__result)       \
        : "z" (__addr16)        \
    );                          \
    __result;                   \
}))

The lpm, short for Load Program Memory, is a instruction that reads a byte of data from PROGMEM area. It substitue a data at addr for __result, then returns the __result.

バージョン

Arduino 1.8.13/avr-gcc 7.3.0-atmel3.6.1-arduino

Last Update

June 19, 2020

inserted by FC2 system