23 Load and Store Global
The following pseudoinstructions are available to load from and store to global objects:
-
l\{b|h|w|d\} \<rd\>, \<symbol expression\>: load byte, half word, word or double word from global -
l\{bu|hu|wu\} \<rd\>, \<symbol expression\>: load unsigned byte, half word, or word from global -
s\{b|h|w|d\} \<rd\>, \<symbol expression\>, \<rt\>: store byte, half word, word or double word to global -
fl\{h|w|d|q\} \<rd\>, \<symbol expression\>, \<rt\>: load half, float, double or quad precision from global -
fs\{h|w|d|q\} \<rd\>, \<symbol expression\>, \<rt\>: store half, float, double or quad precision to global
The following example shows how these pseudoinstructions are used:
lw a0, var1
fld fa0, var2, t0
sw a0, var3, t0
fsd fa0, var4, t0
Which generates the following assembler output and relocations
as seen by objdump:
0000000000000000 \<.text>:
0: 00000517 auipc a0,0x0
0: R_RISCV_PCREL_HI20 var1
4: 00052503 lw a0,0(a0) # 0 \<.text>
4: R_RISCV_PCREL_LO12_I .L0
8: 00000297 auipc t0,0x0
8: R_RISCV_PCREL_HI20 var2
c: 0002b507 fld fa0,0(t0) # 8 \<.text+0x8>
c: R_RISCV_PCREL_LO12_I .L0
10: 00000297 auipc t0,0x0
10: R_RISCV_PCREL_HI20 var3
14: 00a2a023 sw a0,0(t0) # 10 \<.text+0x10>
14: R_RISCV_PCREL_LO12_S .L0
18: 00000297 auipc t0,0x0
18: R_RISCV_PCREL_HI20 var4
1c: 00a2b027 fsd fa0,0(t0) # 18 \<.text+0x18>
1c: R_RISCV_PCREL_LO12_S .L0
On RV32, ld \<rd>, \<symbol expression> and sd \<rd>, \<symbol expression>, \<rt> can be used to
generate a sequence including the ld and sd instructions in Zilsd — in
these cases, \<rd> denotes the even GPR in an even-odd GPR pair.