Docsity

Problem on Computational Physics Laboratory - Assignment 1 | PHZ 4151C, Assignments of Physics

Toggle sidebar
bg1
COMPUTATIONAL PHYSICS LAB
PHZ 4151C/5156C
Homework 1
Due in class, Tuesday, January 22.
Chapter 3 “Introduction to computer and software architecture”: 3.5 Assignments
This assignment is similar to problem (1) in chapter 3 except that we are using the Linux environment
with the gnu compilers. Using an editor create the source code file assemble.cc which contains the
following lines of C++ source code.
#include <iostream>
using namespace std;
int main() {
int i = 3;
int j = 4;
cout << i + j << endl;
}
Now compile this source code using the “-S” g++ option for generating assembly code. The command is
“g++ -S assemble.cc”. This will generate code entitled assemble.s. This new file contains the assembly
language version of the program. Open the file with an editor (or page through the file with more or less,
see “man more” or “man less” for help). Identify the assembly lines which correspond to initializations
of the two integer variables, i & j, and the line(s) which corresponds to the addition of i + j.
Chapter 4 “Fundamental Concepts”: 4.12 Assignments
Do problems 1 - 20

Partial preview of the text

Download Problem on Computational Physics Laboratory - Assignment 1 | PHZ 4151C and more Assignments Physics in PDF only on Docsity!

COMPUTATIONAL PHYSICS LAB

PHZ 4151C/5156C

Homework 1 Due in class, Tuesday, January 22. Chapter 3 “Introduction to computer and software architecture”: 3.5 Assignments This assignment is similar to problem (1) in chapter 3 except that we are using the Linux environment with the gnu compilers. Using an editor create the source code file assemble.cc which contains the following lines of C++ source code. #include using namespace std; int main() { int i = 3; int j = 4; cout << i + j << endl; } Now compile this source code using the “ S” g++ option for generating assembly code. The command is “g++ S assemble.cc”. This will generate code entitled assemble.s. This new file contains the assembly language version of the program. Open the file with an editor (or page through the file with more or less, see “man more” or “man less” for help). Identify the assembly lines which correspond to initializations of the two integer variables, i & j, and the line(s) which corresponds to the addition of i + j. Chapter 4 “Fundamental Concepts”: 4.12 Assignments Do problems 1 20