ARM硬件架构 程序员

ARM汇编之文字池

2018-07-11  本文已影响1人  赵国开

文字池(Literal pools)其实就是一个存储常量数据的地方,汇编器会使用文字池来在代码段中存储常量数据。有时候你需要配合使用LTORG来确保文字池是在程序能够寻址的访问内。

汇编器会在每个段的末尾放置文字池,怎么判断是段的末尾,出现END之后或者出现AREA之前(被include的文件中的END并不算)

在一个大的代码段中,有可能默认的文字池位置是超出LDR能访问的范围的。LDR中相对PC的偏移值需要符合下面条件才是能寻址的(LDR rn, [pc, #offset])

使用 LDR Rd,=const这条伪指令处理时,常量需要放置在文字池中,汇编器的具体寻址过程如下:

下面是参考文档的一个例子:

 AREA     Loadcon, CODE, READONLY
        ENTRY                      ; Mark first instruction to execute
start
        BL       func1             ; Branch to first subroutine
        BL       func2             ; Branch to second subroutine
stop
        MOV      r0, #0x18         ; angel_SWIreason_ReportException
        LDR      r1, =0x20026      ; ADP_Stopped_ApplicationExit
        SVC      #0x123456         ; A32 semihosting (formerly SWI)
func1
        LDR      r0, =42           ; => MOV R0, #42
        LDR      r1, =0x55555555   ; => LDR R1, [PC, #offset to
                                   ; Literal Pool 1]
        LDR      r2, =0xFFFFFFFF   ; => MVN R2, #0
        BX       lr
        LTORG                      ; Literal Pool 1 contains
                                   ; literal Ox55555555
func2
        LDR      r3, =0x55555555   ; => LDR R3, [PC, #offset to
                                   ; Literal Pool 1]
        ; LDR r4, =0x66666666      ; If this is uncommented it
                                   ; fails, because Literal Pool 2
                                   ; is out of reach
        BX       lr
LargeTable
        SPACE    4200              ; Starting at the current location,
                                   ; clears a 4200 byte area of memory
                                   ; to zero
        END                        ; Literal Pool 2 is inserted here, 
                                   ; but is out of range of the LDR
                                   ; pseudo-instruction that needs it

参考文献

【1】DUI0801I_armasm_user_guide

上一篇 下一篇

猜你喜欢

热点阅读