Avr asm label*2

我怕爱的太早我们不能终老 提交于 2019-12-19 10:26:08

问题


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.


回答1:


  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.



回答2:


Its like this. Follow the diagram below..diagrams help a lot in visualizing.

Word Addresses..................................Byte Addresses

|--(0d)---;--(0c)---|06                         |--------|06
|--(0b)---;--(0a)---|05                         |--------|05                          
|--(09)---;--(08)---|04                         |--------|04
|--(07)---;--(06)---|03                         |--------|03
|--(05)---;--(04)---|02                         |--------|02
|--(03)---;--(02)---|01                         |--------|01
|--(01)---;--(00)---|00                         |--------|00

So you see 0x01 word address would correspond to 0x02 byte address 0x04 word address would correspond to 0x08 byte address

Hence the multiply by two.Lets say you have stored your message at location.

.org 0x0200
message:
.db "1234567890#"

In case you are using avr studio and check the program memory section. then you will find this stored in 0x400 not at 0x200.



来源:https://stackoverflow.com/questions/19305155/avr-asm-label2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!