CS 410 assignment 1 C++ to Assembly Activity
.docx
keyboard_arrow_up
School
Southern New Hampshire University *
*We aren’t endorsed by this school
Course
410
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
3
Uploaded by BailiffSpider1312
CS 410 C++ to Assembly Activity Template
Step 1: Explain the functionality of the C++ code.
This code calculate the area by multiplying the width and height and then displays the calculated area.
C++ Code Functionality
C++ Line of Code
Explanation of Functionality
#include<iostream>
Includes the header file iostream
using namespace std;
Uses the standard namespace
int main()
Creates a function that returns an integer int width=10;
Declares the width variable int height=5;
Declares the height variable
int area;
Declares the area variable and assigns area to an
integer
area = width * height; Uses the mathematical equation to find the area
cout<<endl<< area;
Prints out the calculated area
return 0;
Returns functions value and exits the program
Step 2: Convert the C++ file into assembly code.
Step 3: Align each line of C++ code with the corresponding blocks of assembly code.
C++ to Assembly Alignment
C++ Line of Code
Blocks of Assembly Code
using namespace std;
ZStL19piecewise_construct:
.zero
1
.local
_ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.text
.globl
main
.type
main, @function
int main()
main:
.LFB1493:
.cfi_startproc
pushq
%rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq
%rsp, %rbp
.cfi_def_cfa_register 6
subq
$16, %rsp
int width=10;
movl
$10, -12(%rbp)
int height=5;
movl
$5, -8(%rbp)
int area;
movl
-12(%rbp), %eax
area = width * height; imull
-8(%rbp), %eax
movl
%eax, -4(%rbp)
cout<<endl<< area;
movl
-4(%rbp), %eax
movl
%eax, %esi
movq
%rdx, %rdi
call
_ZNSolsEi@PLT
return 0;
movl
$0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
In C++Using the code provided belowDo the Following:
Modify the Insert Tool Function to ask the user if they want to expand the tool holder to accommodate additional tools
Add the code to the insert tool function to increase the capacity of the toolbox (Dynamic Array)
USE THE FOLLOWING CODE and MODIFY IT:
#define _SECURE_SCL_DEPRECATE 0
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class GChar
{
public:
static const int DEFAULT_CAPACITY = 5;
//constructor
GChar(string name = "john", int capacity = DEFAULT_CAPACITY);
//copy constructor
GChar(const GChar& source);
//Overload Assignment
GChar& operator=(const GChar& source);
//Destructor
~GChar();
//Insert a New Tool
void insert(const std::string& toolName);
private:
//data members
string name;
int capacity;
int used;
string* toolHolder;
};
//constructor
GChar::GChar(string n, int cap)
{
name = n;
capacity = cap;
used = 0;
toolHolder = new…
arrow_forward
C++ Array Expander -Just do everything in main and make sure you comment each step Use Pointer Notation for the function and within the function. Use a main function and return the pointer from the ArrayExpander function to main
arrow_forward
C++ Coding: ArraysTrue and False
Code function definitions for eoNum() and output():
Both eoNum() and output() are recursive functions.
output() stores the even/odd value in an array. Store 0 if the element in the data array is even and store 1 if the element in the data array is odd.
eoNum() displays all the values in an array to the console.
arrow_forward
Object Oriented Programming
C++ Language
please use comment
arrow_forward
Programming: Simple Arrays Assignment Instructions
Overview
You will use the enumerated type and a switch to calculate the weight someone would have on another planet.
Instructions
Use a functional decomposition to write a C++ program that asks the user to enter his or her weight and the name of a planet.
Use an enumerated type called planetType to represent the planets and use a switch statement that takes as its condition a planetType variable. The program, via the switch statement, then outputs to the screen how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet.
Your program must have the following functions in it:
GetUserInput()
ConvertInputToPlanetType()
OutputWeight() (your switch statement must be in OutputWeight()).
Determine what each function’s parameters and return types should be. The program will output an error message if the user does not type a correct planet…
arrow_forward
C Programming:
Need help in how to create the code instrumentation in c.
We will rely on gcc's option -finstrument-functions to execute code to collect data at the start and end of invoking any function in a program. This is also called code profiling. For this, you need to implement the following functions in this unit:
void __cyg_profile_func_enter(void *this_fn, void *call_site);
void __cyg_profile_func_exit(void *this_fn, void *call_site);
When we compile our programs with the above-mentioned option, function__cyg_profile_func_enter() will be called at the beginning of all functions in our program and function __cyg_profile_func_exit() will be called at the end of those functions. Parameters this_fn and call_site indicate pointers to the code segment that refer to the profiled function and the instruction that has invoked the profiled function.
We can implement various functionalities using these enter/exit functions to help us analyze the function calls in our program. In this…
arrow_forward
C++
arrow_forward
TRUE OR FALSE, C++
When passing an array to a function, you must include & in front of the array name.
When passing an array to a function, you must include & in front of the array name.
It is possible to have a 2-dimensional array where each row has a different number of columns.
The * is called the address of operator.
arrow_forward
C++ language
Write a program using Switch statement to perform the following functionalities.1. Press a to call functionOne.2. Press b to call functionTwo.3. Press c to call functionThree.4. Exit as any other key pressed.(default)functionOne will return product of all integers entered by user in array of size 8.functionTwo will perform greatest value in array entered by user.funtionThree will calculate lowest value in an array entered by user.
arrow_forward
C++, functions and arrays (please don't use hard or high level code)
arrow_forward
parameter list can also contain the data type of the output of function : true/false
a function declared int addition (int a and b) is capable of returning one value back to the main loop : true/false
main () is a void function: true / false
the address returned by the reference pointer is always the same regardless of operating system: true/false
a function declares as int addition (int a, int b) has a and b as output arguments : true/ false
arrow_forward
5A in Python language please:
arrow_forward
In C++ I need to compose a function that accepts an array of integer values as an argument and returns the total of the values in the array
arrow_forward
Instructions
Write a program in C++ that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions:
Function getData: This function reads and stores data in the two-dimensional array.
Function averageHigh: This function calculates and returns the average high temperature for the year.
Function averageLow: This function calculates and returns the average low temperature for the year.
Function indexHighTemp: This function returns the index of the highest high temperature in the array.
Function indexLowTemp: This function returns the index of the lowest low temperature in the array.
These functions must all have the appropriate parameters.
An example of the program is shown below:
Enter high temperature for each month 60 68 72 72 73 76 80 81 75 72 67 66 Enter low temperature for…
arrow_forward
Function 4: Spell Correction _spellCorrection( string1, string2 ) Create a JavaScript function expression that meets the following requirements: • Authored using function expression syntax (constant name _spellCorrection) • Receives two strings, the first argument is a correct string, the second argument is an incorrect string. • The first argument, the correct string, represents what is supposed to be typed • The second argument, the incorrect string, represents what was provided • The function returns an array of all keys that were missed (what were supposed to be provided) o The returned array should be ordered by when they first appear in the sentence • Only one broken key per letter should be listed (see example 6) • If second argument, is greater in length than the first argument, the function simply returns “invalid” in the returned array (see example 5). • The first argument could be greater in length than the second (see example 2, example 3) • Console log output is NOT…
arrow_forward
c++ program
Q2 Write a C++ program to store values in a two-dimensional array i.e., 3x4 and then write a function that displays the elements of the array. You should take input in the main function and then pass the array to a “PrintArray” function. The function will print the array on the display.
arrow_forward
Using C++ Programming language:
Assume the following definition in the main() function:
const int SIZE = 5;
const int nums[SIZE] = { 18, 17, 12, 14, 16 };
Assume the following function call:
numFunc(nums, SIZE);
Write the function header that accepts these function call arguments without error. Use pointer notation for the array.
arrow_forward
c++ programming
Write a function named maxCols which stores the maximum value in each row of a 3x3 2D array into a 1D array. This function should accept a 3x3 2D array, a 1D array and the size of each dimension as parameters.
Example Calling maxCols with this 2D array:3 7 2 9 3 6 8 5 6 Results in the 1D array storing the values 7,9,8.
arrow_forward
Please code in C++ IDE USE COMMENTS AND EXPLAIN CODE PLEASE
arrow_forward
Function 4: Spell Correction
_spellCorrection ( stringl, string2 )
Create a JavaScript function expression that meets the following requirements:
Authored using function expression syntax (constant name _spellCorrection)
• Receives two strings, the first argument is a correct string, the second argument is an incorrect string.
• The first argument, the correct string, represents what is supposed to be typed
• The second argument, the incorrect string, represents what was provided
The function returns an array of all keys that were missed (what were supposed to be provided)
o The returned array should be ordered by when they first appear in the sentence
Only one broken key per letter should be listed (see example 6)
If second argument, is greater in length than the first argument, the function simply returns "invalid" in the
returned array (see example 5).
• The first argument could be greater in length than the second (see example 2, example 3)
• Console log output is NOT permitted.…
arrow_forward
C++ programming
Chapter(s) Covered:
Chapter 1-8
Concepts tested by the program:
Working with one dimensional parallel arrays
Use of functions
Use of loops and conditional statements
Project Description
The Lo Shu Magic Square is a grid with 3 rows and 3 columnsshown below.
The Lo Shu Magic Square has the following properties:
The grid contains the numbers 1 – 9 exactly. Each number 1 – 9must not be used more than once. So, if you were to add up thenumbers used,
The sum of each row, each column and each diagonal all add upto the same number,
Write a program that simulates a magic square using 3 onedimensional parallel arrays of integer type.
Each one the arrays corresponds to a row of the magicsquare.
The program asks the user to enter the values of the magicsquare row by row and informs the user if the grid is a magicsquare or not.
See the sample outputs for more clarification.
Project Specifications
Input for this project:
Values of the grid (row by row)
Output for this…
arrow_forward
Problem 27 - Arrays
C++ program pls
arrow_forward
In C language
arrow_forward
C code Blocks
Write the complete function that receives a pointer to the array's first element as an argument and multiplies the third element of the array by 10.
Define your function in the same way as the given function prototype.
Take a look at the "For example" below to see how the function is used in the main function and the expected result.
#include <stdio.h>#include <stdlib.h>void multiplyElement(int *ptr);int main(){ int array[5] = {1,2,3,4,5}; int *arrPtr = NULL; arrPtr = &array[0]; multiplyElement(arrPtr); for(int i = 0; i < 5; i++){ printf("%d ", array[i]); }return 0;}//Your answer starts here
For example:
Test
Result
int array[5] = {1,2,3,4,5}; int *arrPtr = NULL; arrPtr = &array[0]; multiplyElement(arrPtr); for(int i = 0; i < 5; i++){ printf("%d ", array[i]); }
1 2 30 4
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Related Questions
- In C++Using the code provided belowDo the Following: Modify the Insert Tool Function to ask the user if they want to expand the tool holder to accommodate additional tools Add the code to the insert tool function to increase the capacity of the toolbox (Dynamic Array) USE THE FOLLOWING CODE and MODIFY IT: #define _SECURE_SCL_DEPRECATE 0 #include <iostream> #include <string> #include <cstdlib> using namespace std; class GChar { public: static const int DEFAULT_CAPACITY = 5; //constructor GChar(string name = "john", int capacity = DEFAULT_CAPACITY); //copy constructor GChar(const GChar& source); //Overload Assignment GChar& operator=(const GChar& source); //Destructor ~GChar(); //Insert a New Tool void insert(const std::string& toolName); private: //data members string name; int capacity; int used; string* toolHolder; }; //constructor GChar::GChar(string n, int cap) { name = n; capacity = cap; used = 0; toolHolder = new…arrow_forwardC++ Array Expander -Just do everything in main and make sure you comment each step Use Pointer Notation for the function and within the function. Use a main function and return the pointer from the ArrayExpander function to mainarrow_forwardC++ Coding: ArraysTrue and False Code function definitions for eoNum() and output(): Both eoNum() and output() are recursive functions. output() stores the even/odd value in an array. Store 0 if the element in the data array is even and store 1 if the element in the data array is odd. eoNum() displays all the values in an array to the console.arrow_forward
- Object Oriented Programming C++ Language please use commentarrow_forwardProgramming: Simple Arrays Assignment Instructions Overview You will use the enumerated type and a switch to calculate the weight someone would have on another planet. Instructions Use a functional decomposition to write a C++ program that asks the user to enter his or her weight and the name of a planet. Use an enumerated type called planetType to represent the planets and use a switch statement that takes as its condition a planetType variable. The program, via the switch statement, then outputs to the screen how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. Your program must have the following functions in it: GetUserInput() ConvertInputToPlanetType() OutputWeight() (your switch statement must be in OutputWeight()). Determine what each function’s parameters and return types should be. The program will output an error message if the user does not type a correct planet…arrow_forwardC Programming: Need help in how to create the code instrumentation in c. We will rely on gcc's option -finstrument-functions to execute code to collect data at the start and end of invoking any function in a program. This is also called code profiling. For this, you need to implement the following functions in this unit: void __cyg_profile_func_enter(void *this_fn, void *call_site); void __cyg_profile_func_exit(void *this_fn, void *call_site); When we compile our programs with the above-mentioned option, function__cyg_profile_func_enter() will be called at the beginning of all functions in our program and function __cyg_profile_func_exit() will be called at the end of those functions. Parameters this_fn and call_site indicate pointers to the code segment that refer to the profiled function and the instruction that has invoked the profiled function. We can implement various functionalities using these enter/exit functions to help us analyze the function calls in our program. In this…arrow_forward
- C++arrow_forwardTRUE OR FALSE, C++ When passing an array to a function, you must include & in front of the array name. When passing an array to a function, you must include & in front of the array name. It is possible to have a 2-dimensional array where each row has a different number of columns. The * is called the address of operator.arrow_forwardC++ language Write a program using Switch statement to perform the following functionalities.1. Press a to call functionOne.2. Press b to call functionTwo.3. Press c to call functionThree.4. Exit as any other key pressed.(default)functionOne will return product of all integers entered by user in array of size 8.functionTwo will perform greatest value in array entered by user.funtionThree will calculate lowest value in an array entered by user.arrow_forward
- C++, functions and arrays (please don't use hard or high level code)arrow_forwardparameter list can also contain the data type of the output of function : true/false a function declared int addition (int a and b) is capable of returning one value back to the main loop : true/false main () is a void function: true / false the address returned by the reference pointer is always the same regardless of operating system: true/false a function declares as int addition (int a, int b) has a and b as output arguments : true/ falsearrow_forward5A in Python language please:arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr