Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22006

LDR pseudoinstruction

$
0
0

when I create ARM assembly code from C code with gcc -S, I get a variant of the LDR instruction that I don't know. Specifically, I get the "ldr r3, .L5" instruction where ".L5" is a lable defined by the compiler. It is not clear to me why I don't get the pseudoinstruction "ldr r3, =.L5", which should be the only way to load an arbitrary number in a register.

More in details:

  1. I start from this C code (file name: sum_squares_C.c):
int sum;

int main(){
    sum = 0;
    for(int i=1; i<=n; i++){
            sum = sum + i*i;
    }
}
  1. Then on a Raspeberry PI, I compile with "gcc -O0 -S sum_squares_C.c", with compiler version gcc (Raspbian 8.3.0-6+rpi1) 8.3.0.

  2. The output is this ARM code (the instruction "ldr r3, .L5" is in the 7th line after label "main"):

    .arch armv6
    .eabi_attribute 28, 1
    .eabi_attribute 20, 1
    .eabi_attribute 21, 1
    .eabi_attribute 23, 3
    .eabi_attribute 24, 1
    .eabi_attribute 25, 1
    .eabi_attribute 26, 2
    .eabi_attribute 30, 6
    .eabi_attribute 34, 1
    .eabi_attribute 18, 4
    .file   "sum_squares_C.c"
    .text
    .global n
    .data
    .align  2
    .type   n, %object
    .size   n, 4
n:
    .word   1
    .comm   sum,4,4
    .text
    .align  2
    .global main
    .arch armv6
    .syntax unified
    .arm
    .fpu vfp
    .type   main, %function
main:
    @ args = 0, pretend = 0, frame = 8
    @ frame_needed = 1, uses_anonymous_args = 0
    @ link register save eliminated.
    str fp, [sp, #-4]!
    add fp, sp, #0
    sub sp, sp, #12
    ldr r3, .L5
    mov r2, #0
    str r2, [r3]
    mov r3, #1
    str r3, [fp, #-8]
    b   .L2
.L3:
    ldr r3, [fp, #-8]
    ldr r2, [fp, #-8]
    mul r2, r2, r3
    ldr r3, .L5
    ldr r3, [r3]
    add r3, r2, r3
    ldr r2, .L5
    str r3, [r2]
    ldr r3, [fp, #-8]
    add r3, r3, #1
    str r3, [fp, #-8]
.L2:
    ldr r3, .L5+4
    ldr r3, [r3]
    ldr r2, [fp, #-8]
    cmp r2, r3
    ble .L3
    mov r3, #0
    mov r0, r3
    add sp, fp, #0
    @ sp needed
    ldr fp, [sp], #4
    bx  lr
.L6:
    .align  2
.L5:
    .word   sum
    .word   n
    .size   main, .-main
    .ident  "GCC: (Raspbian 8.3.0-6+rpi1) 8.3.0"
    .section    .note.GNU-stack,"",%progbits

It seems to me that gcc uses the instruction "ldr r3, .L5" as equivalent to "ldr r3, =.L5". Is it correct? Where can I find the definition of this instruction syntax? Is it possible to force gcc to not use this instruction, but use "ldr r3, =.L5" (I need this for teaching reasons)?

Thanks! Francesco


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>