Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

ASM help please

62 views
Skip to first unread message

Tao Liu

unread,
Aug 5, 2024, 9:17:51 AM8/5/24
to RISC-V SW Dev
hi, group, 

I am trying the risc v assembly language. I compiled the following code. The code is to read the hart id to t6.

.text
.globl _start
_start:
    csrr    t6, mhartid

    add a0, x0, 22
li a7, 93
ecall

But it generates "Illegal instruction" error. I just write this file to a .s file. I used as + ld and generated an executable ELF. If i replace the "CSRR t6, mhartid" to other instruciton (e.g. addi t6, t6, 1), it's fine. 

Does anyone know why CSRR is so special? 

thanks.  

Tommy Murphy

unread,
Aug 5, 2024, 9:44:51 AM8/5/24
to Tao Liu, RISC-V SW Dev
What is the command line that you use to compile it? 

Are you sure that you're specifying a RISC-V architecture that encompasses the optional Zicsr extension? E.g.

riscv64-unknown-elf-gcc -march=rv64gc_zicsr -mabi=lp64d ...

Tao Liu

unread,
Aug 5, 2024, 9:47:41 AM8/5/24
to RISC-V SW Dev, tommy_...@hotmail.com, Tao Liu
my code is in test.s and i use the following two commands get the executable:

  1. riscv64-linux-gnu-as -o csrr.out test.s
  2. riscv64-linux-gnu-ld -o csrr.elf csrr.out
If i replace the CSSR with ADDI, there is no error. 

Tommy Murphy

unread,
Aug 5, 2024, 9:53:17 AM8/5/24
to Tao Liu, RISC-V SW Dev
Unless the toolchain was configured with a default RISC-V architecture that encompasses the optional Zicsr extension that's not going to work and you need to specify the correct arch as I already said. E.g. riscv64-unknown-elf-gcc -march=rv64gc_zicsr etc.

It's generally better to call the GCC front end program riscv64-unknown-elf-gcc rather than the individual back end tools such as as, ld etc.


Reply all
Reply to author
Forward
0 new messages