the piece of code below is mentioned in 8-bit AVR's instruction set as an example to explain the LPM instruction.

ldi ZH, high(Table_1<<1) ldi ZL, low (Table_1<<1) lmp r16, Z ... Table_1: .dw 0x5876 ...

screenshot of the code

I get that it's trying to load the address of flash memory word, labeled "Table_1", into Z register and then one byte of that word (depending on LSB of Z) into r16 register (or maybe I'm wrong about this part. please correct me if I am). What I don't get is the left shift in the first two lines. Can someone please explain why "Table_1" needs to be shifted left before begin loaded to Z?

  • 2
    \$\begingroup\$ google "avr lpm.pdf" there's an entire application note devoted to your question. Alternatively "Rev. 3049A–FPSLI–04/02" is the actual Atmel/microchip document. \$\endgroup\$
    – user201365
    Commented Nov 24, 2018 at 18:39
  • \$\begingroup\$ Amjal - Although you might have to wait another 24hrs (due to a delay imposed by the site), please remember to accept your own answer, so that the site knows that your problem has been solved. Thanks. \$\endgroup\$
    – SamGibson
    Commented Nov 26, 2018 at 18:42

1 Answer 1


I found the answer in the application note:

"The Z-register in the register file is used to access the program memory. This 16-bit register pair is used as a 16-bit pointer to the program memory. The 15 most signifi- cant bits select the word address in program memory. Because of this, the word address is multiplied by 2 before it is put in the Z register."

Thanks to isdi for his comment


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.