问题
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