How to use the .ltorg directive properly to extend the range of LDR Literals

落花浮王杯 提交于 2019-12-25 07:18:05

问题


I'm creating a maze generator in assembly. Now in this particular part of the code, I'm trying to save the current 2D position represented in a 1D array. I'm trying to save the index(.halfword) in the section .data.

//  R1 (CHOICE IS INPUT)
//  R0 (CURRENT POS)
//  R3 (ARRAY2D ADDRESS COPY)
//  R2 (VAL TO STORE)
SETDIRECTIONS:
    MOV     R3, R4      // ARRAY2D ADDRESS
    MOV     R0, R5      // CURRENT POS
    PUSH    {R1}
    LDRH    R1, =POSORIGIN
    STRH    R0, [R1]    // STORE POSITION ORIGIN
    POP {R1}
    CMP R1, #1
    BEQ D1
    CMP R1, #2
    BEQ D2
    ...// More CMP and BEQ Below

.....

D1:
    // UP ONLY
    SUB R0, #17     // 1 ROW UP
    ADD R3, R0      // BASE ADDRESS + CURRENT POS (1 ROW UP)
    MOV R2, #3      // SET AS FLOOR
    STRB    R2, [R3]    // STORE TO ARRAY
    SUB R3, #17     // 1 ROW UP AGAIN
    STRB    R2, [R3]    // SET AS FLOOR

.....

.section .data

POSORIGIN:
    .hword  0

When I try to compile the code, the assembler spits out an error

"Error: invalid literal constant: pool needs to be closer"

Putting SETDIRECTIONS and other functions nearer the section .data solves it, but only a temporary fix. I'm afraid that the longer my codes becomes, the more I will encounter this error.

I searched for a fix and using .ltorg seems to fix these, but I don't know how to use it, There's not enough sample code that I can search in the internet to use it properly

I ran out of registers to use, r5-r10 currently holds something important already. I could push pop them in stack to be saved, but I need access on the current position in some multiple nesting functions where push pop will make it hard for me to trace it back.

来源:https://stackoverflow.com/questions/24153984/how-to-use-the-ltorg-directive-properly-to-extend-the-range-of-ldr-literals

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