i try to translate c to assembly code - (risc-v) but i met this screen and error when i use web risc-v simulator. i use it
https://www.cs.cornell.edu/courses/cs3410/2019sp/riscv/interpreter/ https://riscv.vercel.app/#
but simulators give error that don't read and unknown code to me.
so i think that i mistake for my code or i misused simulator
are you teaching me about my mistake?
this is my assembly code
.data
v:
.word 6, 3, 2, 4, 1, 5 # Array data
.text
.globl main
la a0, v
swap:
slli t1, a1, 2
add t1, a0, t1
lw t0, 0(t1)
lw t2, 4(t1)
sw t2, 0(t1)
sw t0, 4(t1)
ret
sort:
addi sp, sp, -20
sw ra, 16(sp)
sw s6, 12(sp)
sw s5, 8(sp)
sw s4, 4(sp)
sw s3, 0(sp)
mv s5, a0
mv s6, a1
li s3, 0
outer:
bge s3, s6, outerExit
addi s4, s3, -1
inner:
blt s4, zero, innerExit
slli t0, s4, 2
add t0, s5, t0
lw t1, 0(t0)
lw t2, 8(t0)
ble t1, t2, innerExit
mv a0, s5
mv a1, s4
jal ra, swap
addi s4, s4, -1
j inner
innerExit:
addi s3, s3, 1
j outer
outerExit:
lw s3, 0(sp)
lw s4, 4(sp)
lw s5, 8(sp)
lw s6, 12(sp)
lw ra, 16(sp)
addi sp, sp, 20
ret
main:
# Calculate the number of elements in the array
li a1, 6 # 6 elements in the array
# Call the sort function
jal ra, sort
# Exit the program
li a7, 10 # Exit system call
ecall
when i write this code i used my lecture sources and chat gpt
correct my faults - if i use misknoledge recommend risc-v web simulator recommend risc-v tutorial site or pdf or etc