Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

assembly - llvm-gcc assembler: LDR syntax

This code compiles just fine on gcc, but when using llvm (llvm-gcc), it says "constant expression expected" on the line with ldr

The problem is the syntax: How do I specify the place where my array is? I do not want to hard-code the displacement in bytes: ldr r7, [pc, #some_shift] but to use a literal to keep the code clean and safe.

Any idea how to make it working?

.globl func_name

func_name:
     push   {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr}

//[Some stripped code]

     add    r6, r6, sl, lsl #2
     sub    ip, ip, sl
     ldr    r7, =maskTable           // Here it crashes
     add    sl, sl, #4  @ 0x4

// Some stripped code here

     mov    r0, #0  @ 0x0 // return 0
     pop    {r4, r5, r6, r7, r8, r9, sl, fp, ip, pc}

     .word  0x00000000

.data
.align 5
maskTable:

    .word  0x00000000, 0x00000000, 0x00000000, 0x00000000
    .word  0x0000FFFF, 0x00000000, 0x00000000, 0x00000000
    .word  0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try changing

ldr r7, =maskTable

to

ldr r7, maskTable

and remove

.data

section. It seems to be a bug/missing capability of gcc < 4.6 to deal with .data section


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...