19)
Ans)
The Assembly code for the given C function is given below
clearly:
Assembly code:
func(long long, long long): ; function name
pushq %rbp
movq %rsp, %rbp
movq %rdi, -24(%rbp)
movq %rsi, -32(%rbp) ;performing instructions
movq $0, -8(%rbp)
movq $0, -16(%rbp)
.L3:
movq -16(%rbp), %rax ;performing instructions
cmpq -32(%rbp), %rax
jge .L2
movq -24(%rbp), %rax
addq %rax, -16(%rbp) ;add instruction executing
addq $1, -8(%rbp)
jmp .L3
.L2:
movq -8(%rbp), %rax
popq %rbp
ret
Hope This Helps, if you have any doubts Please comment i will get back to you, thank you and please thumbs up
19. (4 points) Convert the following C function (a leaf procedure) to an LEGv8 assembly subroutine....
1. (a) Convert the following C function to the corresponding MIPS assembly procedure: int count(int a[], int n, int x){ int res = 0; int i = 0; for(i = 0; i != n; i++) if(a[i] == x) res = res + 1; return res; } Cannot use converter need hard copy!!!
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...
convert C to LEGv8
(an example given below)
Q1 [15] Convert the following C code to LEG. Assume the following variable/register assignments: Base of A i X19 X20 int main { long long int A[6] = {1, 2, e, e, e, e}; for unsigned int i = 0; i < { A[i+2] myFunction (A[ i] , A[i+1] ); } return 0 } 4; i+ //convert to LEG //convert to LEG //convert the entire myFunction to LEG long long int myFunction...
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?...
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,...
Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of lower case to upper is provided below: Let’s look at a subroutine to capitalize all the lower-case letters in the string. We need to load each character, check to see if it is a letter, and if so, capitalize it. Each character in the string is represented with its ASCII code. For example, ‘A’ is represented with a 65 (0x41), ‘B’ with 66 (0x42),...
(d) (20 points) Convert the following C code to ARM assembly. And indicate the HEX values of the Stack and Data sections in the table below. Note: you do not necessary have to fill in each blank space in the table. Address Value ーC Code int Arr [ ]= {2, 13, 5); int main (void) 0xFFFFFFFC StackOxFFFFFFF8 int Sum; Sum-Ar[0]+A+2*Arr[2] return 0 OxFFFFFFF4 0XFFFFFFFO | 0x0001000C Data Ox00010008 0x00010004 000010000 5 point
(d) (20 points) Convert the following C code...
Problem 6(15 Points) MARIE Assembly Programming Develop a MARIE program containing a main function which finds the smallest element of an array T is shown below. The passing arguments and one subroutine function called Sindmin findmin function array and the aro the findmin subroutine functon are the beginning e pseudo code for the subroutine elements of Array1 and Arra array size Continue the following MARIE program to find the smallest ORG 100 Jump Start nt findmin (int "addr, int size)...
3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...
C++
4. (5 points) Identify the following items in the programming code shown below: a. Function prototype, function heading, function body, and function definitions. b. Function call statements, formal parameters, and actual parameters. C. Value parameters and reference parameters. d. Local variables and global variables. 6. Named constants. #include <iostream> //Line 1 using namespace std; //Line 2 const double NUM = 3.5; //Line 3 int temp; //Line 4 void func(int, doubles, char); //Line 5 int main() int num; double one;...