Assignment 4 An Array of Numbers Solution

$30.00 $26.40

Description

Introduction

Until now we have not yet worked with arrays of numbers except for the special case of pre-initialized strings, which are in fact arrays of char. The real purpose of this assignment is to learn how to work with arrays.

Details

The data of all arrays are stored in memory. The limited number of registers do not allow array data to be stored in the micro-processor. We can theoretically make huge arrays because memory today is huge, but this huge storage comes with a cost, namely: speed. Here are two commands that copy data into a register:

mov rbx, r15

mov rbx, [rdx+24]

The first instruction copies a qword of data from a register to a register.

The second instruction copies a qword of data from a memory location to a register.

Expect that the second instruction will require on the order of a thousand more time units than the first instruction.

Requirements

Make of program of comprises the modules shown in the diagram below (or next page).

This document was created using Libre Office Writer. If MS Word is used to view the document it is probable that the diagram on page 2 will become corrupted.

There are five functions (modules) in this program. The language of the source of each module is shown in the lower right corner of the box. The arrows show which module calls which other modules.

The Main module. This module outputs the title of the program. It outputs information about the person made this program. It might even say something about the author: “The author is an avid fan of multilingual program and assembly programming.” or something like that.

The main module calls the Control module. When the control module terminates the main module outputs the value sent by the Control module. The main module wishes the user to have a very nice day and to come back soon.

The Control module. This module output information about the program and its activities. It explains to the user what to expect. Then it asks the user “Are you ready? Press ‘c’ to continue or ‘x’ to exit.”

The Control module declares an empty array of quadword integers in the bss segment. This module in X86 calls the Fill module to get data from the user’s keyboard.

The Control module calls the Display module to show the user the data the users has just finished entering. The Control module asks the user “Are these values correct (y or n)?” If the user inputs any character other than ‘y’ then the process repeats: the Control module calls the Fill module again.

If the user inputs ‘y’ then the Control calls the Sum module. The Sum module adds together all the numbers in the array and passes that total back to the control module. The Control outputs that number for the user in base 10. Sometimes the sum is negative, and that is ok.

Near the end of the run the Control module sends the sum back to main. Main says thank you for the nice number you sent to me. Main outputs the number in 8-byte hex for the user to inspect it. Then Main returns 0 to the operating system.

Source code languages

Main: C

Control X86

Fill C++

Display C

Sum X86

When you are finished

You are finished when the following happens.

The program runs to completion with no crash (seg fault).

Each module performs its duty correctly.

All outputted numbers are mathematically correct.

The source program is cosmetically pretty to contemplate.

The program is accompanied by a suitable bash file.

When you are finished you are invited to send a copy of your opus to the professor.

After the midterm you should post your accomplishment on Github. Put a link to the program in the resume that you are developing semester by semester. Your job interviewer wants to know and see what you can build.

Due dates are non-productive. A due date conveys the impression that you program late into the night of the day before it is due. You submit the program, and then you do nothing until 24 hours before the next program is due.

In assembly programming we continue to program 7 days per week non-stop. We are just like the real job:

=open notes on the job and open notes during the quizzes and tests

=continuous software development on the job and continuous programming in this course

Start this program as soon as you finish Assignment 3. The due date is as soon as you can finish. You must submit your best version of Assignment 4. That’s how the midterm works. There are no second submissions in Assignment 4 or in the midterm program.