Question: Need help with risc v assembly code to convert the following c programs into riscv assembly #include #include void rstr _ c ( char *

Need help with risc v assembly code to convert the following c programs into riscv assembly
#include
#include
void rstr_c(char *dst, char *src){
int src_len = strlen(src);
int i, j;
for (i =0, j = src_len -1; i < src_len; i++, j--){
dst[i]= src[j];
}
dst[src_len]='\0';
}
Output:
rstr: Reverse a string
$ ./rstr a
C: a
Asm: a
$ ./rstr FooBar
C: raBooF
Asm: raBooF
$ ./rstr "CS315 Computer Architecture"
C: erutcetihcrA retupmoC 513SC
Asm: erutcetihcrA retupmoC 513SC
#include
#include
void rstr_rec_func_c(char *dst, int dst_idx, char *src, int src_idx){
if (src[src_idx]=='\0'){
dst[dst_idx]='\0';
return;
}
// Copy the current character from the end of src to the start of dst
dst[dst_idx]= src[src_idx];
rstr_rec_func_c(dst, dst_idx +1, src, src_idx -1);
}
void rstr_rec_c(char *dst, char *src){
int src_len = strlen(src);
rstr_rec_func_c(dst,0, src, src_len -1);
}
Output:
rstr_rec: Reverse a string recursively
$ ./rstr_rec a
C: a
Asm: a
$ ./rstr_rec FooBar
C: raBooF
Asm: raBooF
$ ./rstr_rec "CS315 Computer Architecture"
C: erutcetihcrA retupmoC 513SC
Asm: erutcetihcrA retupmoC 513SC

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!