Click here to Skip to main content
15,916,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've found similar examples here, but not using RISC-V.
The program is initialized like this:

.data
vector: .word 1 2 3 4 5 6 7
.text
main:
la x12, vetor
addi x13, x0, 7
addi x13, x13, -1
slli x13, x13, 2
add x13, x13, x12
jal x1, reverse
beq x0, x0, END
##### edit start #####
reverse: jalr x0, 0(x1)
##### edit end #####
END: add x1, x0, x10

The procedure receives two memory locations, the start position and the end position of the array

What I have tried:

My guess was something like using srli, but I'm 99.9% sure it's wrong.
Posted
Updated 8-Oct-22 18:45pm
v2
Comments
Dave Kreskowiak 8-Oct-22 22:43pm    
I hate to tell you this, but it's very unlikely you're going to get an answer to this.

RISC processors died out on the desktop a LONG time ago, and searching the history of this site, you are the only person to ever ask a RISC assembly question on this site, and that goes back 20 years.

1 solution

Dave is right: you will be unlikely to find a RISC V programmer here, but it looks like a pretty simple assembler to learn: RISC-V Assembly Programmer's Manual[^] - if you are familiar with any other assembly language, at least. I was an assembly dev for decades, but I never met RISC before!

Start by getting the spelling right:
RISC
vector: .word 1 2 3 4 5 6 7
...
la x12, vetor
No assembler will pass that: vetor is not the same as vector
Then think about what you are doing: that all looks kinda wrong.
RISC
addi x13, x0, 7        Load x13 with 7
addi x13, x13, -1      Load x13 with 6
slli x13, x13, 2       Load x13 with 6 * 4
add x13, x13, x12      Offset vector by 24
Which makes some sense, but you don't use x13 or x12 again at all ...

And why are you trying to reverse an array recursively? it means you need a stack that is at least as big as the array - which is silly - and it's a very inefficient way to do the task.
A simple loop using a temporary register is better:
Assembly
Loop:
    load temp with low address value.
    copy high address value to low address
    load high address value with temp
    repeat via Loop for (N / 2) iterations.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900