Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction This assignment introduces arrays. An array is really the only data

ID: 3733473 • Letter: I

Question

Introduction

This assignment introduces arrays. An array is really the only data structure found natively in X86. Some authors have tried to introduce the concept of “object-oriented assembly programming”, but such attempts are mostly wishful conjecturing. Here we do a basic program with arrays of doubles (64-bit floats)).

Requirements

Make a program consisting of two files: a controller program in C++ or C and a principal function written in X86. The controller program, sometimes called a ‘driver’ is not part of the solution. It exists simply as a reminder that C++, X86, and C are all friends living in one neighborhood. Also, C++ has the best linker of the three languages mentioned above.

The driver program displays a welcome message and calls the assembly function. The assembly function does the following:

            = Displays an introductory message

            = Instructs the user to input a sequence of doubles and terminate with cntl+D.

            = Outputs the numbers in the array

            = Finds the largest number in the array.

            = Finds the smallest number in the array.

            = Swaps position between the largest and smallest

            = Outputs the numbers in the modified array

            = Display a closing message

            = Returns control to the driver.

There is no error checking for invalid inputs.

On the next page is a sample run. Make your program produce output as close to the sample as possible. Output all numbers with 18 decimal digits on the right side of the decimal point.

Sample execution

This is CPSC 240 Assignment 2 programmed by Paris Hilton.

This software is running on a MSI GP622 with processor Intel Core i5-5780 running at 2.2GHz with

operating system Ubuntu 17.10.

Welcome to the array program. This program will save your 64-bit data in an array.

Please enter floating point number and press enter after each number. The limit is 10 numbers.

5.9

-11.89

3.12

7.77

2.915

<Cntl+D>            <== Cntl+D is pressed here, but no visible symbol appears.

Thank you for you inputs. Your array is as follows:

5.900000000000000071

-11.89000000000000103

3.120000000000000003

7.770000000000000118

2.915000000000000226

The software is now swapping the largest and smallest numbers in the array. Finished.

Your array is now the following.

5.900000000000000071

7.770000000000000118

3.120000000000000003

-11.89000000000000103

2.915000000000000226

This assembly function will now return to the caller function.

The main function will now return 0 to the operating system. Have a nice program.

Explanation / Answer

#include <stdio.h>

float findLargest();

float findSmallest();

void swapLargestAndSmallest();

float a[10];

int n,i;

float largest=0, smallest=0;

void main()

{

printf(“WELCOME USERS ”);

printf("Enter 10 numbers in the array and terminate with CNTRL D ");

for (i=0; i<=9; i++)

scanf("%f", &a[i]);

do{

printf("Enter your choice ");

printf("1. Find largest no 2. Find smallest no 3. Swap largest and smallest no and Display modified array ");

scanf("%d", &n);

switch (n)

{

case 1: largest= findLargest();

break;

case 2: smallest= findSmallest();

break;

case 3: swapLargestAndSmallest();

}

}while(n<=3);

printf(“THANK YOU”);

   

}

float findLargest()

{

largest = a[0];

for (int c = 1; c<10; c++)

{

    if (a[c] > largest)

       largest = a[c];

}

printf("Largest = %f ", largest);

return largest;

}

float findSmallest()

{

smallest = a[0];

for (int c = 1; c<10; c++)

{

    if (a[c] < smallest)

       smallest = a[c];

}

printf("Smallest = %f ", smallest);

return smallest;

}

void swapLargestAndSmallest()

{

int pos1, pos2;

float temp1, temp2;

largest=findLargest();

smallest=findSmallest();

for(i=0;i<n;i++)

{

if(smallest==a[i])

{

pos1=i;

break;

}

}

for(i=0;i<n;i++)

{

if(largest==a[i])

{

pos2=i;

break;

}

}

temp1=a[pos1];

temp2=a[pos2];

a[pos1]=temp2;

a[pos2]=temp1;

printf("Modified array ");

for(i=0;i<10;i++)

printf(" %f ",a[i]);

}

NOW, TO RUN IT IN ASSEMBLY LANGUAGE PROGRAM, CALL THIS FUNCTION WITH .globl main

This .globl assembler directive makes the main function visible to linker.

Hope this helps!!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote