AVR: bytewise access of Z register

I have the following code (that works)

; begin

ARRAY: .DB 22,34,56,21 ; define an array of byte

LDI ZL, LOW (2*ARRAY) ; point to address "array"

LPM ; read array[0] e store it in R0

; end

Why I must multiple by 2 the address ARRAY?

On help I read that since the register Z does a bytewise access (instead of a wordwise access) you must multiple by 2 the address.

But I didn't understand exactly the reason.

Thanks in advance

Reply to
[Frank]
Loading thread data ...

Look at the listing:

000002 ARRAY: .DB 22,34,56,21 000002 2216 000003 1538 000004 e0e4 LDI R30,LOW(2*ARRAY) 000005 95c8 LPM

The assembler used word addresses but you need a byte address for accessing program memeory with the LPM instruction.

A decent assembler would also use byte addresses (and calculate the word address for jumps):

00000004: 16 22 38 15 array: dc.b 22,34,56,21 00000008: e0e4 move.b #array,r30 0000000a: 95c8 movePM.b (r31|r30),r0
Reply to
Herbert Kleebauer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.