*
*Home|Chinese|Japanese*About ARM|Forums|Events|News|Employment|Contact Us|Investors*
dotted rule
*ARM - the architecture for the digital worldARM - the architecture for the digital world
search
*
*
***
*MARKETS:PRODUCTS & SOLUTIONS:CONNECTED COMMUNITY:TECHNICAL SUPPORT:DOCUMENTATION*
*
technical support
*
*
****
*.Technical Support
*
*
*>>Home Page*
*
*.Obtaining Support*
*
*.FAQs*
*
**Development Tool FAQs*
**IP FAQs*
**Embedded Software FAQs*
**Artisan Physical IP FAQs (Login Required)*
*
*.Downloads*
*
*.Documentation*
*
*.Training*
*
*.Where To Buy*
*
*.Keil MCU Tools*
*
*.What's New*
*
*.ARM Newsgroups*
*
*.Active Assist On-site Services*
*
*
*
technical support FAQsask ARM*
*

Technical Support Search
*     (Advanced Search)
  FAQs   Documentation   Downloads   Forums

*

 
downarrowarmasm/tasm: What does '#label-.-8' mean?
Applies to: Assembler, Software Development Toolkit (SDT)

The '.' (or its equivalent '{PC}', which must be in upper case) means 'the address of this instruction', as documented in the SDT 2.50 Reference Guide , section 5.4 (and the SDT 2.11 Reference Guide, section 2.6.4).

It is commonly used in PC-relative instructions, for example:

        :
LDR r0, [pc, #label-.-8]
:
label DCD 0x1234
:

This could alternatively be written as:

        :
LDR r0,[pc,#label-{PC}-8]
:
label DCD 0x1234
:

and is equivalent to:

        :
this LDR r0,[pc,#label-this-8]
:
label DCD 0x1234
:

In most circumstances, there is a much easier syntax for the instruction above:

        :
LDR r0,label
:
label DCD 0x1234
:

In short, '{PC}' or '.' allows an instruction to refer to its own address, without forcing the programmer to find a unique label ('this ' above) each time.

Note that '{PC}' is not the same as 'PC'.
'PC' (or 'pc ') is an alternative way of referring to the ARM register 15, which contains the program counter.

'label-{PC}-8' calculates the address of 'label' minus the address of this instruction (to get the difference between the two addresses in bytes), minus 8. This subtraction of 8 is needed because when the LDR instruction reads the program counter, the value it will get is its own address plus 8. On many (but not all) ARMs, this is also the address of the instruction being fetched by the pipeline at the time, i.e. the program counter points to the instruction being fetched, not the one being executed.

For similar instructions in Thumb code, the value 4 needs to be subtracted rather than 8 , as the pc actually reads as the address of the instruction 2 ahead of the current one, and Thumb instructions are 2 bytes long compared with 4 bytes for an ARM instruction.

'label-{PC}-8' results in an immediate offset which is then applied to the program counter to form the address of the memory location containing 0x1234. The resulting memory location is read and the value (0x1234) placed into r0 .

The reason for the continued use of '.' is historical - to maintain compatibility with existing software written with earlier versions of the Assembler. For all new software, the use of '{PC} ' is recommended instead.






back to top

*
**
*4 dots*Other ARM Websites
*
shadow *LEGAL STATEMENTshadow