Translate the following C code into RISC-V Assembly. (no need to implement the prints just use ecall)
int a[] = {2,2,5,3,4,8,3};
int b[] = {1,4,2,0,-1,5,4};
int z[7];
void multiply(int* a, int* b, int* c, int d)
{
for (int i=0; i < d; i++) {
c[i] = a[i] * b[i];
}
}
int main()
{
int n = 7;
multiply(a,b,z,n);
printf("%s", "res: ");
for (int i = 0; i < z; i++)
{
printf("%d", d[i]);
}
printf("\n");
return 0;
}
# multiply function starts
multiply:
# Load all the arguments
lw x9, a0 # x9 = a
lw x10, a1 # x10 = b
lw x15, a3 # x15 = c
lw x16, a4 # x16 = d
# initilaze variables
addi x9, x8, 0 # x9=&a[0]
addi x10, x8, 0 # x10=&b[0]
addi x11, x0, 0 # i=0
Loop:
lw x12, 0(x9) # x12=a[i]
lw x13, 0(x10) # x13=b[i]
add x14,x12,x13 # x[14] = a[i]+b[i]
lw 0(x15), x14 # c[i] = x[14]
addi x9,x9,4 # &a[i++]
addi x10,x10,4 # &b[i++]
addi x15,x15,4 # &c[i++]
addi x11,x11,1 # i++
addi x13,x0,x16 # x13=d
blt x11,x13,Loop
# jump to calling function
jr ra
Translate the following C code into RISC-V Assembly. (no need to implement the prints just use...
IN RISC-V
a) Consider the RISC-V code below. Indicate what is the value in register x20 after the code below is executed, and explain why; ori x18 x0 16 addi x20 x18 0 beq x20, x18, HERE add x20 x20, x20 b) Assume that the code above is part of a procedure called by main. What happens with the stack pointer during the procedure execution and why? Draw and explain. c) Add instructions to the above code to implement your...
please code using risc-v language and make it as simple as
possible
Problem 1: (20 marks) Part 1: (15 points) Compile the RISC-V assembly code for the following C code. Assume that n and k are passed in x3 and x4 respectively. Values n and k are initialized to 14 and 14. Assume that result returned in register fl and that double precision numbers are used. After you are done store the result in address: 12(x3). Are you allowed to?...
Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...
Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() { int number; scanf("%d", &number); if (number % 2 == 0) { printf("Even\n"); } else { printf("Odd\n"); } return 0; }
Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void change_global(int value) { counter = counter + value; } void main() { change_global(5); change_global(10); }
Translate the following C code into assembly
BIT PONG #define Led(1) = 0.01 #define Led(2) = 0.02 #define Led(3) = 0.01 #define Led(4) = 0.08 #define Led(5) = 0.10 #define Led(6) = 0.10 #define Led(7) = #define Led(8) = Unsigned int_delay (){ do a--i while (a! = 0) return } int main (void) { while (1) { int a = 1000 i volatile int i = 0: for { delay(a): }
Please do the following problems 1. translate into RISC-V Assembly variable rpt in x19 register. if(rpt>0){ rpt=rpt-1; goto loop } 2. Translate the following Risc-V code into C. variable 'i' in register x5, variable 'result' in x6 ,base address of integer 'memarray' in x10 addi x6,x0,0 addi x29,x0,100 LOOP: ld x7,0(x10) add x5,x5,x7 addi x10,x10,8 addi x6,x6,1 blt x6,x29, LOOP
How would you translate the following from Java to RISC-V? static int Y1[] = {13, 101, 79, 23, 154, 4, 11, 38, 88, 45, 17, 94, 62, 1}; static int lenY1 = 14; public static void main(String[] args) { quickSort(Y1,lenY1); } public static void quickSort(int[] x, int n) { qSort(x,0,n-1); }
Translate the High order language program to assembly language and generate PEP9 assembly language code. #include <stdio.h> int main() { int number; scanf(“%d”,&number ); if (number <0) { number =- number; } printf ("%d", number); return0; }
MIPS assembly language
Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value