Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab, you will write an X86-64 assembly language program which has 5 functions, with the C language function prototypes shown below: int main();

For this lab, you will write an X86-64 assembly language program which has 5 functions, with the C language function prototypes shown below: int main(); void multInts(int size, int *array1, int *array2); void addShorts(short size, short *array1, short *array2); void invertArray(int size, int *array1); void printArray(int size, int *array1); See below for a description of what each of these functions should do. PROBLEM: Write an assembly language program with five procedures or functions using X86-64. The program should have 4 static arrays, defined in the data section of the program (that is, stored on the heap), including two int arrays, intArray1 and intArray2, both of the same size, and two short arrays, shortArray1 and shortArray2, both of the same size. There should also be two other variables defined in the data section, one of which is an int, sizeIntArrays, and will hold the size of the int arrays, and the other of which is a short, sizeShortArrays, and will hold the size of the short arrays. Do not change any of these labels in the data section (case matters!). Required data section: .data sizeIntArrays: .long 4 sizeShortArrays: .word 5 intArray1: .long 10 .long 25 .long 33 .long 48 intArray2: .long 20 .long -37 .long 42 .long -61 shortArray1: .word 69 .word 95 .word 107 .word 12 .word 332 shortArray2: .word 27 .word -87 .word 331 .word -49 .word -88 CONSTRAINTS: Your program must have five procedures/functions, with the labels main, multInts, addShorts, invertArray, and printArray (Do not change these: case matters!). You need to write the main procedure to call the other four procedures at appropriate points, and with the appropriate parameters in the correct 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 multInts procedure should first call printf to print Products on one line, and then multiply the first value in the first int array, intArray1, times the first value in the second int array, intArray2, and call printf to write the result to output on a separate line, then multiply the second value in the first int array times the second value in the second int 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 int array, and the second value in the same position in the second int array. A blank line should be printed at the end of all of the products. The addShorts procedure should first call printf to print Sums, and then add the first value in the first short array, shortArray1, to the last value in the second short array, shortArray2, and call printf to write the sum to output, then add the second value in the first short array to the second from the last value in the second short array, and call printf to write the sum to output, and so on, for each of the n pairs of values in the two arrays consisting of one value at index position i in the first short array, and the second value at index position n 1 i in the second short array. A blank line should be printed at the end of all of the sums. The printArray 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 Elements in intArray1, and then, on the following lines, print the values in the array it is passed in order, from the first value to the last value, one value per line. printArray should be called with a pointer to intArray1, 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 intArray1, but prints no output. The elements in intArray1, after they are placed in inverse order by invertArray, will be printed out by procedure printArray, below, which will be called from main after the invertArray procedure returns to main. The printArray procedure should be called the second time after the call to, and return from, invertArray. It first calls printf to print Elements in intArray1, 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 intArray1 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. To pass values to procedures, you must use the appropriate registers, as discussed in class and shown in the class slides. You should also follow the X86-64 conventions discussed in class, and covered in the class slides, related to caller and callee save registers, and returning values from procedures in register rax or an appropriate subregister. Remember that you need to put format strings in read only memory in order to call printf to print output, as well as passing the values of any variables to be printed in the appropriate register(s). See the first X86-64 program in the class slides for examples of how to do this. OUTPUT: For the sample input given above, the output should be as follows: Products 200 -925 1386 -2928 Sums -19 46 438 -75 359 Elements in intArray1 10 25 33 48 Elements in intArray1 48 33 25 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

What is the purpose of a C++ constructor?

Answered: 1 week ago