# Initialize 64-bit variables

**URL:** <https://forums.sifive.com/t/initialize-64-bit-variables/978>\
**Category:** RISC-V\
**Created:** [January 12, 2018, 2:51am UTC](https://forums.sifive.com/t/initialize-64-bit-variables/978 "2018-01-12T02:51:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rp15](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rp15](https://forums.sifive.com/u/rp15)\
**Post date:** [January 12, 2018, 2:51am UTC](https://forums.sifive.com/t/initialize-64-bit-variables/978/1 "2018-01-12T02:51:05Z")

</div>

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)

```

…  
.LC0:  
.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?

Thanks,  
Ron

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [January 12, 2018, 3:03pm UTC](https://forums.sifive.com/t/initialize-64-bit-variables/978/2 "2018-01-12T15:03:28Z")

</div>

You can find instruction definitions in the ISA manual.  
[https://riscv.org/specifications/](https://riscv.org/specifications/)  
There is a blog that talks about how relocations work  
[https://www.sifive.com/blog/2017/08/21/all-aboard-part-2-relocations/](https://www.sifive.com/blog/2017/08/21/all-aboard-part-2-relocations/)

Jim

---

<div class="post-metadata">

**Author:** ![rp15](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rp15](https://forums.sifive.com/u/rp15)\
**Post date:** [January 12, 2018, 6:56pm UTC](https://forums.sifive.com/t/initialize-64-bit-variables/978/3 "2018-01-12T18:56:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rp15](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rp15](https://forums.sifive.com/u/rp15)\
**Post date:** [January 12, 2018, 8:59pm UTC](https://forums.sifive.com/t/initialize-64-bit-variables/978/4 "2018-01-12T20:59:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [January 12, 2018, 11:24pm UTC](https://forums.sifive.com/t/initialize-64-bit-variables/978/5 "2018-01-12T23:24:10Z")

</div>

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