Lab11
.docx
keyboard_arrow_up
School
University of Massachusetts, Lowell *
*We aren’t endorsed by this school
Course
2030
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
3
Uploaded by BarristerRoseMouse35
COMP.2030
LAB
11/29/23
NAME _____________________________________________
1.
A recursive C function,
recur
, is declared as
int recur(long *x, long y)
is compiled into the x86 code on the right.
Complete the C code of the function
recur
below.
int
recur(
long
*x,
long
y) {
recur: pushq
%rbp
movq
%rsp, %rbp
subq
$16, %rsp
movq
%rdi, -8(%rbp)
movq
%rsi, -16(%rbp)
cmpq
$0, -8(%rbp)
jne
.L2
movl
$-1, %eax
jmp
.L3
.L2:
cmpq
$10, -16(%rbp)
jne
.L4
movl
$0, %eax
jmp
.L3
.L4:
movq
-8(%rbp), %rax
movq
(%rax), %rax
cmpq
-16(%rbp), %rax
jle
.L5
movq
-8(%rbp), %rax
addq
$8, %rax
movq
(%rax), %rax
movq
-16(%rbp), %rdx
movq
%rdx, %rsi
movq
%rax, %rdi
call
recur
addl
%eax, %eax
jmp
.L3
.L5:
movl
$1, %eax
.L3:
leave
ret
2.
The function
long switch_prob(long x, long n)
is disassembled as shown below.
long switch_prob(long x, long n) {
long result = x;
switch(n) {
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Recreate the following C program in x86-64 and aarch64 assembly manually:
#include <stdio.h>
typedef struct _v2d {long x;long y;} v2d_t;
static long dot(v2d_t a, v2d_t b){return a.x * b.x + a.y * b.y;}
static long dot_ptr(v2d_t *a, v2d_t *b){return a->x * b->x + a->y * b->y;}
int main(void){v2d_t a, b;
scanf("%ld %ld %ld %ld", &a.x, &a.y, &b.x, &b.y);
long res1 = dot(a, b);printf("%ld\n", res1);
long res2 = dot_ptr(&a, &b);printf("%ld\n", res2);
return 0;}
arrow_forward
Solve the question with C ++
arrow_forward
in c++
2. Consider an array of 30 elements is stored in the memory of 120 bytes from 3000 to
3116. Find out the address of 13ª index element.
arrow_forward
in c++
5. Assume you have given an array A[15][20]. Each element needs 'W' bytes of storage. If
the address of A[6][8] is 4440 and the base address at A[1][1] is 4000, find the width 'W'
of each cell in the array A when the array is stored as Column Major Wise.
arrow_forward
QUESTION 2
Specify all that is true regarding the asterisk symbol for C++.
The symbol is used for getting the memory address of a variable.
The symbol is used for multiplication.
O The symbol is use for dereferencing a pointer.
O The * symbol is used for decalring a pointer.
arrow_forward
Question:- 1
Recreate the following C program in x86-64 and aarch64 assembly manually:
#include <stdio.h>
typedef struct _v2d {long x;long y;} v2d_t;
static long dot(v2d_t a, v2d_t b){return a.x * b.x + a.y * b.y;}
static long dot_ptr(v2d_t *a, v2d_t *b){return a->x * b->x + a->y * b->y;}
int main(void){v2d_t a, b;
scanf("%ld %ld %ld %ld", &a.x, &a.y, &b.x, &b.y);
long res1 = dot(a, b);printf("%ld\n", res1);
long res2 = dot_ptr(&a, &b);printf("%ld\n", res2);
return 0;}
arrow_forward
Suppose you have the following C++ code:
int* average; // Defines int pointer variables
int* gradesArray;
Show the single line of C++ code that creates a new int variable and store its address into average. Show the single line of C++ code that creates an eight-element array and stores the base address of the array into gradesArray.
Using the example, show the lines of C++ code that deallocate the dynamic data.
arrow_forward
plz help with c++....and keep output same as given and paste indented code plzz
arrow_forward
Write a C program that uses the following:
a main() to read two integer values from the user, val1 and val2, and prints the returned value from swap().a swap() that uses call by reference (takes the addresses into pointers) to swap values, and prints their values after the swap "num1 = # and num2 = #". This function returns the largest of the two values. If these are equal, it returns their sum.
arrow_forward
Please solve quickly Object-oriented programming in c++
arrow_forward
The program below uses pointer arithmetic to determine the size of a 'char' variable. By using pointer arithmetic we can find out the value of 'cp' and the value of 'cp+1'. Since cp is a pointer, this addition involves pointer arithmetic: adding one to a pointer makes the pointer point to the next element of the same type. For a pointer to a char, adding 1 really just means adding 1 to the address, but this is only because each char is 1 byte. Compile and run the program and see what it does. Write some code that does pointer arithmetic with a pointer to an int and determine how big an int is. Same idea – figure out how big a double is, by using pointer arithmetic and printing out the value of the pointer before and after adding 1. What should happen if you added 2 to the pointers from exercises 1 through 3, instead of 1? Use your program to verify your answer
#include <stdio.h>int main( ) { char c = ‘Z’; char *cp = &c; printf("cp is 0x%08x\n", cp); printf("The character…
arrow_forward
s. Convert the following C code to assembly language
using vector operations. (Just do your best, make
necessary assumptions, don't worry about syntax too
much.)
for (i-0;i <300; i++) {
c_re[i] = a_re[i] b_re[i]-a_im[i] * b_im[i]:
c_im[i] - a_re[i] b_im[i]+a_im[i] * b_re[i];
arrow_forward
Demonstrate how the gdb debugger can be utilized in aiding the establishment of Pointer assignment error
language: C
Perform debugging in Ubuntu Linux 16, i.e.
Use only the gdb debugger.
give the following screenshots:1code
2load program to gdb
3set break point
4fixed code
5load proggram ingdb again with fixed code
arrow_forward
Write a C++ program that sorts a one-dimensional array in ascending
and descending order, provided that the sorting process is using the
overload function.
Write a C++ program that add, subtract, multiply and division two-
dimensional arrays provided the operations is using the overload
function.
arrow_forward
. C supports three (and only three) forms of pointer arithmetic: Adding an integer to a pointer, subtracting an integer from a pointer, and subtracting one pointer from another. What is the one pointer arithmetic operation that C does NOT support?
arrow_forward
The addressing mode which makes use of in-direction pointers is
А.
Relative addressing mode
В.
Offset addressing mode
C.
Index addressing mode
D.
Indirect addressing mode
arrow_forward
c++
arrow_forward
Note: Please solve using c++ programming Language.
arrow_forward
In C, write a function that gets 3 pointers int* a, int* b, int* c, and rotates the values in their addresses to the left. That is, a gets the value of b, b gets the value of c, and c gets the value of a.
void rotate3 (int* a, int* b, int* c);
For example,
if we have int x=1, y=2, z=3, then after calling rotate3 (&x, &y, &z) we should have x==2, y==3, and z==1.
if we have int x=7, y=1, z=6, then after calling rotate3 (&x, &y, &z) we should have x==1, y==6, and z==7.
arrow_forward
Assembly language
arrow_forward
Write a C function that is given a pointer to memory, the number of bytes of memory the pointer points at, and two pointers to uint32_t. Your job is to treat the pointer as if it were a pointer to an array of uint32_t, find the min and max values of the array, and write the results to the locations pointed at by the uint32_t pointers.
The number of bytes will be a positive multiple of 4. Do not worry about endianess in this problem.
Note the tester has command line options -Wall -Wextra -Werror -fsanitize=address to help you catch errors.
arrow_forward
in c++
1. Consider an array of 20 elements is stored in the memory of 40 bytes from 200 to 238.
Assume array index starts from 3. Find out the address of 10th index element.
arrow_forward
Write a program in C++ that contains code addressing the following: (New code and with detailed steps!)
a. Create an integer array of 100,000 items (static binding – before
compiling)
b. Create the same large array on the run time stack (in a function)
c. Create the same large array from the heap (dynamic memory –
dynamic binding).
Call each of the subprograms 1,000,000 times and output the time required by
each to finish all 1,000,000 calls. Which was the fastest?
Here is code for calling time.
#include <time.h>
//in main()
clock_t start = 0, end = 0; //variables
start = clock(); //calls time function stores result in start
end = clock(); // calls time function stores result in end
//display the time by subtracting the start from the end
//displays in clock ticks.
arrow_forward
In C++, please explain in detail
Declare an integer variable XYZ and a pointer called XYZpointer. Write the C++ statemens that will correcty make pointer variable XYZpointer point to the storage location XYZ and extract its address.
arrow_forward
Language: C
Write a C program that allocates memory using the malloc function for an array of size specified by the user at runtime. Assign pseudo-random double values to the array elements, then sort the array using the qsort function. Using the examples from the lecture, define a function that compares numbers of type double. Pass the function address to the qsort function. Use the free function to free up memory.
Problem 1 and Problem 2.
arrow_forward
C program. It should strictly follow the 3 rules.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Related Questions
- Recreate the following C program in x86-64 and aarch64 assembly manually: #include <stdio.h> typedef struct _v2d {long x;long y;} v2d_t; static long dot(v2d_t a, v2d_t b){return a.x * b.x + a.y * b.y;} static long dot_ptr(v2d_t *a, v2d_t *b){return a->x * b->x + a->y * b->y;} int main(void){v2d_t a, b; scanf("%ld %ld %ld %ld", &a.x, &a.y, &b.x, &b.y); long res1 = dot(a, b);printf("%ld\n", res1); long res2 = dot_ptr(&a, &b);printf("%ld\n", res2); return 0;}arrow_forwardSolve the question with C ++arrow_forwardin c++ 2. Consider an array of 30 elements is stored in the memory of 120 bytes from 3000 to 3116. Find out the address of 13ª index element.arrow_forward
- in c++ 5. Assume you have given an array A[15][20]. Each element needs 'W' bytes of storage. If the address of A[6][8] is 4440 and the base address at A[1][1] is 4000, find the width 'W' of each cell in the array A when the array is stored as Column Major Wise.arrow_forwardQUESTION 2 Specify all that is true regarding the asterisk symbol for C++. The symbol is used for getting the memory address of a variable. The symbol is used for multiplication. O The symbol is use for dereferencing a pointer. O The * symbol is used for decalring a pointer.arrow_forwardQuestion:- 1 Recreate the following C program in x86-64 and aarch64 assembly manually: #include <stdio.h> typedef struct _v2d {long x;long y;} v2d_t; static long dot(v2d_t a, v2d_t b){return a.x * b.x + a.y * b.y;} static long dot_ptr(v2d_t *a, v2d_t *b){return a->x * b->x + a->y * b->y;} int main(void){v2d_t a, b; scanf("%ld %ld %ld %ld", &a.x, &a.y, &b.x, &b.y); long res1 = dot(a, b);printf("%ld\n", res1); long res2 = dot_ptr(&a, &b);printf("%ld\n", res2); return 0;}arrow_forward
- Suppose you have the following C++ code: int* average; // Defines int pointer variables int* gradesArray; Show the single line of C++ code that creates a new int variable and store its address into average. Show the single line of C++ code that creates an eight-element array and stores the base address of the array into gradesArray. Using the example, show the lines of C++ code that deallocate the dynamic data.arrow_forwardplz help with c++....and keep output same as given and paste indented code plzzarrow_forwardWrite a C program that uses the following: a main() to read two integer values from the user, val1 and val2, and prints the returned value from swap().a swap() that uses call by reference (takes the addresses into pointers) to swap values, and prints their values after the swap "num1 = # and num2 = #". This function returns the largest of the two values. If these are equal, it returns their sum.arrow_forward
- Please solve quickly Object-oriented programming in c++arrow_forwardThe program below uses pointer arithmetic to determine the size of a 'char' variable. By using pointer arithmetic we can find out the value of 'cp' and the value of 'cp+1'. Since cp is a pointer, this addition involves pointer arithmetic: adding one to a pointer makes the pointer point to the next element of the same type. For a pointer to a char, adding 1 really just means adding 1 to the address, but this is only because each char is 1 byte. Compile and run the program and see what it does. Write some code that does pointer arithmetic with a pointer to an int and determine how big an int is. Same idea – figure out how big a double is, by using pointer arithmetic and printing out the value of the pointer before and after adding 1. What should happen if you added 2 to the pointers from exercises 1 through 3, instead of 1? Use your program to verify your answer #include <stdio.h>int main( ) { char c = ‘Z’; char *cp = &c; printf("cp is 0x%08x\n", cp); printf("The character…arrow_forwards. Convert the following C code to assembly language using vector operations. (Just do your best, make necessary assumptions, don't worry about syntax too much.) for (i-0;i <300; i++) { c_re[i] = a_re[i] b_re[i]-a_im[i] * b_im[i]: c_im[i] - a_re[i] b_im[i]+a_im[i] * b_re[i];arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr