Question
One of the very practical uses of assembly language programming is its ability to optimize the speed and size of computer programs. While programmers do
One of the very practical uses of assembly language programming is its ability to optimize the speed and size of computer programs. While programmers do not typically write large-scale applications in assembly language, it is not uncommon to solve a performance bottle neck by replacing code written in a high level language with an assembly language procedure.
In this programming project you will be given a C++ program that generates an array of pseudorandom integers, sorts the array, and then searches the array for a particular value. The C++ program uses the binary search algorithm to determine if the search value is one of the elements in the array. A binary search procedure is considered an efficient way to search an ordered array.
Your job is to write an assembly language procedure that also performs the binary search. The C++ program will time multiple searches performed by both the C++ code and your assembly language procedure and compare the result. If all goes as expected, your assembly language procedure should be faster than the C++ code.
Chapter 13 of your textbook contains a discussion of how to interface an assembly language procedure with a high-level programming language like C++.
The Visual Studio solution for the C++ program that you are given has been packaged and compressed into a file called ProjectFour.zip. Create a location on your computer for this project. Download the compressed file, ProjectFour.zip, and unpack it into that location in your computer.
Look in the \...\Projects\ProjectFour folder for a file named ProjectFour.sln. The .sln file extension stands for solution. Double clicking on this file will start up the Visual Studio solution for ProjectFour and allow you to execute the C++ program.
Modify ProjectFour by following these steps:
- Click on the project name, ProjectFour in the Solution Explorer pane.
- Click on the Project choice in the menu bar at the top of the screen.
- Select Build Customizations.
- In the Visual C++ Build Customization Files dialog box, check the checkbox next to masm(.targets,.props). Choose OK to save your selection and close the dialog box.
- On the menu bar, choose Project, then choose Add Existing Item.
- In the Add New Item dialog box, select the file named AsmBinarySearch.asm. Choose Add to add the file to your project and close the dialog box.
Use Ctrl+F5 or click on Debug in the Menu Bar followed by Start Without Debugging to execute the program. The MASM assembler will assemble AsmBinarySearch.asm into an object file that is then linked into your project.
A stub assembly language procedure has been provided so that you can execute the C++ program to get a feel for how it works. Your job is to improve on the efficiency of the C++ compiled code. Click on the file named AsmBinarySearch.asm in the Solution Explorer pane. This file is your starting point for creating an assembly language version of the binary search routine.
As always, start small. DO NOT be the Cookie Monster and gobble up the whole project at once. Steps you might consider, but are not limited to are:
- Have your assembly language procedure return the number of elements in the array. This will tell you if what is being passed as an argument is the value you expected.
- Have your assembly language procedure return the value of the first element in the array. This will tell you if you understand how to address and retrieve the value of an element in the array.
- Have your procedure return the second (or fifth) element in the array.
- Calculate the subscript of the middle element in the array and return the value of that subscript. This will confirm that you can make one of the calculations needed to implement the binary search and retrieve a particular element in the array.
- Calculate the subscript of the middle element in the array and return the value of that element in the array. This will confirm that you can retrieve any element in the array.
This project will provide you with the opportunity to:
- Link an assembly language procedure to an existing C++ program.
- Demonstrate your ability to work with a one-dimensional array.
- Show that you can implement a while loop in assembly language.
- Display your understanding of what an assembly language procedure is and how they can be used.
- Provides a chance for you to show that you understand how to compare values and take conditional action based on the results.
- Observe how assembly language procedures can be used to optimize programs written in a high-level language like C++.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started