Question: For this lab, you will write an X8664 assembly language program which has 5 functions, with the C language function prototypes shown below: int main();
For this lab, you will write an X8664 assembly language program which has 5 functions, with the C language function prototypes shown below:
int main(); void multQuad(long size, long *array1, long *array2); void invertArray(long size, long *array1); void printQArray(long size, long *array1);
See below for a description of what each of these functions should do.
PROBLEM:
Write an assembly language program with four procedures or functions using x8664. The program should have 2 64bit arrays, defined in the data section of the program, QArray1 and QArray2. There should also be one other long variable defined in the data
section, sizeQArrays, which will hold the size of the 64 bit arrays. Do not change anyof these labels in the data section (case matters!).
Required data section: .data sizeQArrays: .quad 6
QArray1: .quad 10 .quad 25 .quad 33 .quad 48 .quad 125 .quad 550
QArray2: .quad 20 .quad 37 .quad 42 .quad 61 .quad 75 .quad 117
CONSTRAINTS: Your program must have four procedures/functions, with the labels main, multQuads,
invertArray, and printQArray (Do not change these: case matters!).
You need to write the main procedure to call the other three procedures at appropriate points, and with the appropriate parameters in registers to pass to the procedures, so that they do what is described below. You are allowed to do other work in main to get parameter values to pass to the procedures before you call them, but NO OUTPUT SHOULD BE PRINTED FROM main.
The multQuads procedure should first call printf to print the string, Products, on one line, and then multiply the first value in the first quad array, QArray1, times the first value in the second quad array, QArray2, and call printf to write the result to output on a separate line, then multiply the second value in the first quad array times the second value in the second quad array, and write the result to output on a separate line, and so on, for each pair of values consisting of one value from the first quad array, and the second value in the same position in the second quad array. A blank line should be printed at the end of all of the products.
The printQArray procedure will be called twice, the first time before the call to invertArray, and the second time after. It should first call printf to print the string, Elements in QArray1, and then, on the following lines, print the values in the array it ispassedinorder,fromthefirsttothelast,onevalueperline. printArrayshouldbe
called with a pointer to QArray1, as well as the size of the array it is to print. It should also print a blank line following all of the values in the array.
The invertArray procedure should invert, or reverse, the elements in QArray1, but print no output. The elements in QArray1, after they are placed in inverse order by invertArray, will be printed out by procedure printQArray, below.
The printQArray procedure should be called the second time after the call to, and return from, invertArray. It first calls printf to print Elements in QArray1, and then, on the following lines, print the values in the array it is passed in order, from the first to the last, one value per line. printArray should be called the second time with a pointer to QArray1 after the elements are inverted, or reversed, by invertArray, to print out the elements in the opposite order which they were originally in. It will also be passed the size of the array it is to print. It should also print a blank line following all of the values in the array.
After PrintQArray procedure has been called the second time, MultQuads should be called a second time.
To pass values to procedures, you must use registers. You cannot pass parameters on the stack.
You should also follow the x8664 conventions as specified in the X86 slides, conventions related to caller and callee save registers, caller cleanup, and returning values from procedures in register rax.
Remember that you need to put format strings in read only memory in order to call printf to print output.
OUTPUT: For the sample input given above, the output should be as follows:
Products
200
925
1386
2928
9375
64350
Elements in QArray1
10 25 33
48
125
550
Elements in QArray1
550 125 48
33
25
10
Products
11000
4625
2016
2013
1875
1170
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
