Initialize 64-bit variables

Hi all,

Here’s the following C code:

void main()
long long int a = 0x7aaabbbb80001111;

After the command

riscv64-unknown-elf-gcc-7.1.1 -Dmarch=rv64i -S -o store.s store.c

I get the following asm instruction pair to initialize the variable ‘a’:

    lui     a5,%hi(.LC0)
    ld      a5,%lo(.LC0)(a5)

.dword 8839083632648786193
.ident “GCC: (GNU) 7.1.1 20170509”

Although ‘a’ gets the intended value (0x7aaabbbb80001111 == 8839083632648786193), I do not understand how the lui and ld instructions achieve this. I.e., what is the exact definition of %hi(.LC0), %lo(.LC0)(a5), .LC0, and .dword?


You can find instruction definitions in the ISA manual.
There is a blog that talks about how relocations work


That blog entry about relocations is exactly what I needed, thank you!

I’ve been thinking, during which step of the flow does the constant (0x7aaabbbb80001111 == 8839083632648786193) get written into data memory? So that ld can be used to initialize the variable.

The compiler put the value in a data section. It gets loaded into memory when the program is loaded into memory.