I'm trying to learn RISC-V assembly using gas and ld. I'm running my code natively on a Devterm R-1. My issue is that the la pseudoinstruction does not seem to always give me a usable memory address when I use .asciz. Here is what I have:
Filename m.asm
.global start
.text
_start:
la a1, w1
la a2, w2
la a3, w3
la a4, w4
la a5, w5
nop
addi a0, x0, 0
addi a7, x0, 93
ecall
.data
w1: .asciz "Odd"
w2: .asciz "Even"
w3: .asciz "NineChars"
w4: .asciz "\n"
w5: .asciz "I"
I built an executable with these commands:
as m.asm -g -o m.o
ld m.o -o m
And tested with:
gdb m
I stepped down to the nop instruction and used p to print the memory addresses stored at each register:
a1 = 69912
a2 = 69916
a3 = 69921
a4 = 183252031331
a5 = 183252031333
The first three look reasonable and do indeed contain data if I use x/c to view the contents as characters. However, trying to do the same to a4 or a5 gives me a cannot access memory at address... error.
System details: OS is: "Linux devterm-R01 5.4.61 #12 PREEMPT Wed Mar 30 14:44:22 CST 2022 riscv64 riscv64 riscv64 GNU/Linux"
gas is version is 2.39 ld is version 2.39 gdb is version 12.1
Ask: Can someone educate me into what is happening with the memory addresses returned by la on these .asciz strings? As they are they are unusable.