Description Below are examples of how to take addresses of code labels in an area containing both ARM and Thumb labels. The examples use the 'LDR =' pseudo-instruction but the same rules apply to 'DCD label'. In an AOF object file produced by armasm (SDT 2.50/2.51), a code area has the attribute THUMB if the assembler is in CODE16 state at the time the AREA directive is processed. This is called a Thumb area in the text below. A code area without this attribute is called an ARM area. If you wish to take the address of a code label in another area, the behaviour depends on the type of the target area, and the state of the target symbol. Solution If the type of the target address is the same as the area in which it is declared, no manual adjustment is required; otherwise, you will need to add one or subtract one to obtain the correct address. There are four cases to consider:
; Case 1. Taking the address of an ARM symbol which is in an ARM area. ; This behaves as documented and as expected CODE32 AREA from1arm,CODE ENTRY LDR r0,=target1
CODE32 AREA to1ARM,CODE target1 MOV pc,lr
; Case 2. Taking the address of a Thumb symbol which is in an ARM area. ; Need explicitly to add one to the target address CODE32 AREA from2Thumb,CODE LDR r0,=target2 + 1 ;; because Thumb target in ARM area
CODE32 AREA to2ARM,CODE CODE16 target2 MOV pc,lr
;3. To an ARM symbol in a Thumb area. ;; Assembler bug makes this impossible to express. ;; Suggested workaround: change your code to avoid using Thumb areas, ;; i.e. use CODE32 before declaring each new AREA CODE32 AREA from3ARM,CODE LDR r0,=target3 ;; r0 ends up containing target3 + 1 LDR r0,=target3 - 1 ;; r0 ends up containing target3 - 1
CODE16 AREA to3Thumb,CODE CODE32 target3 MOV pc,lr
; Case 4 Taking the address of a Thumb symbol which is in a Thumb area. ; This behaves as documented and as expected CODE16 AREA from4ARM,CODE LDR r0,=target4
CODE16 AREA to4Thumb,CODE target4 MOV pc,lr
END
|