Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

assembly - Avr asm label*2

Hi i am new in avr asm programming,in the example below, i have few questions:

1) Is it label: 8 bit or 16bit long?

2) Why multiplication label with 2 is needed?

3) Instruction LPM is placing their result in register R0? If so, what does that have to do with Z?

4) Can you explaine the quoted text from the provided link:

"If the address is not multiplied by two and label is at byte address 0x60 (word address 0x30), Z will point at the code stored there. I hope this clarified the addressing problem. Other versions are"

ldi ZL, low(2*label)
ldi ZH, high(2*label)

label:
.db "Hello world", 0
lpm

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Label is 16 bits.
  2. Because the assembler is using word addresses, but LPM needs byte address. Note that not all assemblers do this, notably gas that's used by avr-gcc, doesn't. Then you don't need the multiplication.
  3. Yes, the no-operands version of LPM automatically loads into R0, and it takes the address from Z. See the instruction set reference.
  4. That wasn't too clear LOL, but see #2, above.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...