please code using risc-v language and make it as simple as possible
//RISC-V assembly code for the above-given question
//the execution program following as
//the code as follows fo rthe above given question
.file "code.cpp"
.text
.section .rodata
.type _ZStL19piecewise_construct, @object
.size _ZStL19piecewise_construct, 1
_ZStL19piecewise_construct:
.zero 1
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.text
.globl _Z4funcii
.type _Z4funcii, @function
_Z4funcii:
.LFB1493:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $18, -4(%rbp)
jle .L2
movl $0, %eax
jmp .L3
.L2:
cmpl $1, -4(%rbp)
jg .L4
movl $1, %eax
jmp .L3
.L4:
cmpl $2, -8(%rbp)
jg .L5
movl -4(%rbp), %eax
jmp .L3
.L5:
cmpl $17, -8(%rbp)
jle .L6
movl $1, %eax
jmp .L3
.L6:
cmpl $3, -4(%rbp)
jg .L7
movl $5, %eax
jmp .L3
.L7:
movl -8(%rbp), %eax
leal 1(%rax), %edx
movl -4(%rbp), %eax
subl $2, %eax
movl %edx, %esi
movl %eax, %edi
call _Z4funcii
cvtsi2sd %eax, %xmm0
movsd .LC0(%rip), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -16(%rbp)
movl -8(%rbp), %eax
leal -3(%rax), %edx
movl -4(%rbp), %eax
addl $1, %eax
movl %edx, %esi
movl %eax, %edi
call _Z4funcii
cvtsi2sd %eax, %xmm0
movsd .LC1(%rip), %xmm1
mulsd %xmm1, %xmm0
movsd -16(%rbp), %xmm1
addsd %xmm0, %xmm1
cvtsi2sd -8(%rbp), %xmm0
movsd .LC2(%rip), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm0, %xmm1
movl -4(%rbp), %eax
leal 3(%rax), %edx
testl %eax, %eax
cmovs %edx, %eax
sarl $2, %eax
cvtsi2sd %eax, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
.L3:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1493:
.size _Z4funcii, .-_Z4funcii
.globl main
.type main, @function
main:
.LFB1494:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $14, -8(%rbp)
movl $14, -4(%rbp)
movl -4(%rbp), %edx
movl -8(%rbp), %eax
movl %edx, %esi
movl %eax, %edi
call _Z4funcii
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1494:
.size main, .-main
.type _Z41__static_initialization_and_destruction_0ii,
@function
_Z41__static_initialization_and_destruction_0ii:
.LFB1975:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L12
cmpl $65535, -8(%rbp)
jne .L12
leaq _ZStL8__ioinit(%rip), %rdi
call _ZNSt8ios_base4InitC1Ev@PLT
leaq __dso_handle(%rip), %rdx
leaq _ZStL8__ioinit(%rip), %rsi
movq _ZNSt8ios_base4InitD1Ev@GOTPCREL(%rip), %rax
movq %rax, %rdi
call __cxa_atexit@PLT
.L12:
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1975:
.size _Z41__static_initialization_and_destruction_0ii,
.-_Z41__static_initialization_and_destruction_0ii
.type _GLOBAL__sub_I__Z4funcii, @function
_GLOBAL__sub_I__Z4funcii:
.LFB1976:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1976:
.size _GLOBAL__sub_I__Z4funcii, .-_GLOBAL__sub_I__Z4funcii
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I__Z4funcii
.section .rodata
.align 8
.LC0:
.long 0
.long 1074397184
.align 8
.LC1:
.long 0
.long 1071644672
.align 8
.LC2:
.long 0
.long 1074003968
.hidden __dso_handle
.ident "GCC: (Ubuntu 7.3.0-16ubuntu3) 7.3.0"
.section .note.GNU-stack,"",@progbits
//End of program
-------------------------------------------------------------------------------------------------------
%%%%%%%%%%%% PLEASE GIVE ME POSITIVE RATING%%%%%%%%%%%%%%%%%
Problem 1: (20 marks) Part 1: (15 points) Compile the RISC-V assembly code for the following C co...
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; }
Problem 1 (15 points) Translate the C code below into RISC-V, knowing that the values of i and j are in registers x28 and x29, respectively. The base address of array B is in register x30, and the base address of array C is in register x31.
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
Write a MIPS assembly code that corresponds to the following C code. Note: use the stack to store all register values that you use in the procedures. int aver(int * array, int N){ int i, sum = 0; for ( i=0;i i<N; i++) sum += array[i]; return sum/N;} int Max( int * array, int N){ int i, Maximum = array[i]; for ( i = 1; i< N; i++) if ( array[i] > Maximum) Maximum = array[i]; return Maximum; } int...
Problem #2 (20pts) Please write the MIPS assembly code corresponding to the following C code segment. Assume that f is assigned to register $s2 int Example int i, int j, int k) int f; f i+j-k-1: return fi
For the C code 1 int loop while(int a, int b) int result 1; while (a < b) t result (atb); return result; Gcc generates the following assembly code: %ebp+8, mov1 movl movl %ebp+12 at 8(%ebp) ,%ecx 12(%ebp) ,%ebx $1,%eax a at b 5 jge L11 leal (%ebx, %ecx), Xodx 8 L12: inull %eax , %eax addl $1,%ecx addl $1, edx cmp1 %ecx , %ebx 9 10 12 13 J8 14 ·L11: .L12 In generating this code, occ makes an...
a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. long fibonacci (long n) { if (n == 0) return 0; else if (n == 1) return 1; else return (fibonacci (n - 1) + fibonacci (n - 2)); } b) The Windows x86-64 calling convention passes function parameters in the registers RCX, RDX, R8 and R9 and returns values on register RAX. Caller saved registers are: RAX,...
1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...
1. Compile the following C program using the most effective DLX code, similar to the example given in the class. int A[200], B[200], C[200]; ..... for(i=0;i<200;i++) A[i]=B[i]+C[i]*5; Assume array A, B and C each starts at memory location x1000, x2000 and x3000, respectively. You will need to establish each of these addresses in a register (use r1, r2 and r3 for each of the three) before the loop. Also, you need to establish a counter register for “i” (use r4)...
a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. Note: You cannot change the algorithm in any way so your assembly function must still be recursive. (20 points) long Catalan(long n) { long sum = 0; if (n == 0) return 1; for (int i = 0; i < n; i++) { sum += Catalan(i) * Catalan(n - i - 1); } return sum; } b) The...