Page 1

GSP 215 Week 1 -7 All iLab and Homework

FOR MORE CLASSES VISIT www.gsp215rank.com Please check all Included Assignment Details below GSP 215 Week 1 Homework Command Line in Windows and Linux GSP 215 Week 2 iLab Binary Representation of Information GSP 215 Week 2 Homework Representing and Manipulating Information GSP 215 Week 3 Homework Representing and Manipulating Information GSP 215 Week 3 iLab Machine-Level Representation of Programs GSP 215 Week 4 Homework Optimizing Program Performance GSP 215 Week 4 Lab Optimizing Program Performance GSP 215 Week 5 Homework memory Leaks GSP 215 Week 5 iLab GSP 215 Week 6 Homework Assignment GSP 215 Week 6 iLab Virtual Memory GSP 215 Week 7 Homework Assignment GSP 215 Week 7 iLab


GSP 215 Week 7 HomeWork

==============================================

GSP 215 Week 1 Homework Command Line in Windows and Linux

FOR MORE CLASSES VISIT www.gsp215rank.com Week 1 HomeworkCommand Line in Windows and Linux • Using Google, research what kernel operating systems have been used in the video gaming industry. Describe the architecture and details regarding its advantages or disadvantages (i.e, consider Windows, Linux, based, etc.). A minimum of two paragraphs of research information is required, along with your own interpretation of the content. • Using Google, research the use of parallelism and concurrency in video gaming today. Describe how each is used in the building and implementation of video gaming platforms. A minimum of two paragraphs of research information is required, along with your own interpretation of the content. ==============================================


GSP 215 Week 2 Homework Representing and Manipulating Information

FOR MORE CLASSES VISIT www.gsp215rank.com Week 2 Homework Representing and Manipulating Information Part A: Understanding the relationship between hexadecimal, binary, and decimal representations are very important when discussing machine-level programs. 1. Convert the following hexadecimal number to binary and decimal: 5C. 2. Convert the following binary number to hexadecimal and decimal: 00001110. 3. Convert the following decimal number to hexadecimal and binary: 88. 4. Use two's complement to convert the following decimal number to binary: -49. Part B: Knowing the four operations & = AND, | = OR, ^ = Exclusive OR and ~= NOT based on the example in the lecture, solve the following problems. Part C: Explain in your own words the difference between Big Endian and Little Endian.


==============================================

GSP 215 Week 2 iLab Binary Representation of Information

FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 2 iLab Week 2 Lab—Binary Representation of Information Scenario In this lab, we will be using cygwin and Visual Studio to write C++ code to illustrate floating point error and bitwise operations Part A: The goal of this exercise is to introduce you to an important aspect of numerical computing: numerical error. Games use floating point as the primary number representation for almost everything. Coordinate data stored as (x,y,z) is used to represent vertices, which in turn are used to represent triangles, which themselves are used to represent 3D objects. Digital representation of any number must be accomplished with a fixed number of bits, typically 32. However, one third, for example, has no finite representation in fixed-point binary; that is, it would require an infinite number of bits unless one uses floating point. Computation with real numbers can quickly produce results that cannot fit into 32 bits.


When this happens, numbers are rounded to the closest representable number. This introduces numerical error. Evaluating a series of expressions can result in a large error, as demonstrated in this lab. Use single precision floating point for all numbers. Variables need to be declared as float, and constants should be followed by an f suffix, as in 3.14f. 1. Compute the square root of 501.0f, and store the result in a variable float x. 2. Multiply x by itself. Ideally, this would = 2. What do you get? 3. Multiply x by itself again. Ideally, this would = 4. What do you get? 4. Subtract x from the constant 251001.0f. Ideally, this should = 0.0. What do you get? 5. Compute the multiplicative inverse of x (meaning 1/x). In order to avoid dividing by 0.0, first test if x!= 0.0, and only compute inverse if this is true. What do you get? 6. Copy and paste your source code into the lab report below, and paste a screenshot. See an example of the screenshot below. C++ Code: Screenshot: See example below: Part B: Color displays use blends of red, green, and blue (RGB) light to create the colors you see. The digital representation of this concept is to store each red, green, and blue component as an eight-bit unsigned number. The value 255 represents the maximum displayable brightness of a


single component, the color 0 represents no intensity/light, and 128 is halfway between the two extremes. Below are some triples of RGB values and what color they represent. 0, 0, 0 black 255, 255, 255 bright white 255, 0, 0 bright red 0, 128, 0 medium green 128, 128, 0 medium yellow A digital image is a two-dimensional array of RGB values, where each RGB corresponds to an on-screen pixel. For a better understanding, open an image using the program paint (under the accessories menu). Select the color menu, then edit colors, then define custom colors, and play around in the right-hand side of the pane where you can type in RGB component numbers to see what color they represent. Because each component is only eight bits, the 24 bits required for RGB is typically stored in a single 32-bit word rather than separately. This is called a packed RGB format. This is what is used to drive all computer


displays. The hexadecimal representation of orange (full red, half green, no blue) is 0x00FF0800. The representation of half red, half green, half blue is 8421504, in hexadecimal it is: 0x00808080. Write two functions using only shifts and bit-wise logical operations. One takes individual red, green, and blue components as input and returns a single 32-bit word in packed format. The second does the inverse, which is called unpacking. Test your code with some simple examples. First pack the red, green, and blue, and then unpack them to see that you get what you started with. Pay attention to the types of all input and return values to make sure that they use the least number of bits required. All of these should be unsigned numbers (there are no negative colors). You will need to use shift operator. x=y<<4 assigns x the result of shifting y to the left four bits. You will also be using bitwise & (AND) and | (OR). Hint: in unpack, you will need to write code like this: r2=(rgb>>16) &0xff; to unpack the value for red. To pack the values, you will need something like this: rgb = r<<16|g<<8|b; #include <iostream> using namespace std; int pack (int r, int g, int b); ==============================================

GSP 215 Week 3 Homework Representing and Manipulating Information


FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 3 Homework Assignment Week 3 Homeworkâ&#x20AC;&#x201D;Representing and Manipulating Information Structures are a mechanism for creating a data type to aggregate multiple objects into a single unit. All the components of a structure are stored in a contiguous region of memory and a pointer to a structure is the address of its first byte. To access the fields of a structure, the compiler generates code that adds the appropriate offset to the address of the structure. The example on the book on page 242 shows the following structure. struct rec { int i; int j; int a[3]; int *p; }; This structure contains four fields: two 4-byte int's, an array consisting of three 4-byte int's, and a 4-byte int pointer giving a total of 24 bytes. j is offset 4 bytes.


0

4

8

16

20

24

i j a[0] a[1] a[2] p

Assuming variable 4 is of type struct rec * and is in register %edx, the following code copies element r->i to element r->j. movl (%edx), %eax // Get r->i movl %eax, 4(%edx) //Store r->j To store into the field j, the code adds offset 4 to the address of r Consider the following structure declaration containing a structure within a structure, and answer the following questions. struct person{ struct size{ int height; int weight; }s; int *hp; int games[2]; }person1, person2; 1. How many total bytes does the structure require?

height weight hp games[0] games[1]


2. What are the offsets in bytes of the following fields? s.height: ______________ hp:_______________ games[1]:______________ 3. The compiler generates the following assembly code for the body of str_init (shown below). movq

16(%rbp), %rax

movl

4(%rax), %edx

movq

16(%rbp), %rax

movl

%edx, (%rax)

movq

16(%rbp), %rax

leaq 4(%rax), %rdx %rdx

//Get p1 into register %rax //Get p1->s.weight store in register %edx //Get p1 into register %rax //Store in p1->s.height //Get p1 into register %rax //Compute address of p1->s.weight in register

movq

16(%rbp), %rax

//Get p1 into register %rax

movq

%rdx, 8(%rax)

//Store in p1->hp

4. On the basis of this information, fill in the missing expressions in the code for str_init. void str_init(person *p1) { p1->s.height = _____________; p1->hp = _________________; }


5. How would you call str_init with the structperson1 passed to it?

==============================================

GSP 215 Week 3 iLab Machine-Level Representation of Programs

FOR MORE CLASSES VISIT www.gsp215rank.com Week 3 Lab Machine-Level Representation of Programs TCO 3â&#x20AC;&#x201D;Given the need to understand and describe performance bottlenecks, acquire an understanding of how C and C++ is translated into machine code. Scenario In this weekâ&#x20AC;&#x2122;s lab, you will key in and compile a C++-supplied program. Using the instructions provided, you will proceed to inspect, comment, and produce representative assembly code. PART A: We will look at C code versus machine code. Write the following code in cygwin using vi and save it as code.c. Part B:


Linux and Windows show assembly in different formats. The code differences are shown below. Copy the code below into a new Visual Studio Project. Compile the C++ code. In the Solution Explorer, right click on the .cpp file and choose properties.

==============================================

GSP 215 Week 4 Homework Optimizing Program Performance

FOR MORE CLASSES VISIT www.gsp215rank.com Optimizing Program Performance A programmer must write correct code that is clear and concise. There are also circumstances in which a programmer must write fast and efficient code. Processing video frames in real time must be fast. We will talk about ways to optimize code. Given the following code, perform these operations to optimize the code. See Chapter 5 in the book for more details on code optimization. Please use comments to document all optimizations you have made to the code. 1. Using switch instead of if


2. Eliminating length calls out of the loop test 3. Put the most used variables first when initializing variables 4. Use prefix operations rather than postfix operations 5. Loop unrollingâ&#x20AC;&#x201D;increase the number of elements computed in each iteration of a loop (i.e. instead of processing arrays separately, if you have two arrays of the same length, process them in parallel) 6. Any other improvements you want to make #include <iostream> #include <vector> #include <string> using namespace std; #include <iostream> #include <vector> #include <string> using namespace std; int main() { //This program stores the items purchased at the grocery store. The price vector stores the prices for each item purchased. //The product name vector stores the products purchased and the category vector stores which category the item falls under.


//Frozen foods have a 10% discount, snacks has a 5% discount, and produce has a 15% discount. //The total amount of items purchased should be calculated with a 7% tax rate. double sum; double tax,totalAmount; vector<double> price; vector<string>productName; vector<char> category; price.push_back(4.5); price.push_back(10); price.push_back(1.25); price.push_back(2.75); price.push_back(9.50); ==============================================

GSP 215 Week 4 Lab Optimizing Program Performance

FOR MORE CLASSES VISIT www.gsp215rank.com


Week 4 Lab Optimizing Program Performance TCO 4â&#x20AC;&#x201D;Given the importance of speculating runtime costs of software, obtain an understanding of certain details of how processors operate that impact code performance. Scenario In this weekâ&#x20AC;&#x2122;s lab, you will look at timing operations and how different operations can take a different amount of time to complete. Part A: We will look at timing operations in C++. To see the difference in operations, write C++ code to compare cout and printf, and display the time difference for 100 cout operations and 100 printf operations. This code can be written in Visual Studio. Below is how you would time the 100 cout operations in Visual Studio. Add another for loop, and display time for both cout and printf then comment about why you think there is a difference. Part B: Next, we will take timing a step further. There are a few different sorting algorithms, and these algorithms have varying time complexity. For this part of the lab, we will implement bubble sort and quick sort. Research bubble sort and quick sort algorithms, and implement them in C++. Fill a large array (maybe 15,000 elements) of random numbers. Then time the difference between bubble sort and quick sort 10 times, and fill out the table. Next, run the program in release mode. Did you notice a difference in time? Yes, release mode works much faster ==============================================


GSP 215 Week 5 Homework memory Leaks

FOR MORE CLASSES VISIT www.gsp215rank.com Week 5 Homeworkâ&#x20AC;&#x201D;Memory Leaks Memory leaks are bugs in C++ applications that can cause performance problems with your application or even causing it to crash. A memory leak is the result of failing to deallocate memory that was previously allocated. In C++ the commands #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> will enable the debug heap functions. After enabling the debug heap functions, place a call to _crtDumpMemoryLeaks() before an application exit point. Given the following code, run this code in debug mode. The memory leak report will appear in the Output Window with the debug option. It should look something like this.

The output will look like the following.


Detected memory leaks! Dumping objects -> {142} normal block at 0x0079A948, 25 bytes long. Data: <> CD CDCDCDCDCDCDCDCDCDCDCDCDCDCDCD {141} normal block at 0x0079A8F8, 20 bytes long. Data: <Sheldon > 53 68 65 6C 64 6F 6E 00 CD CDCDCDCDCDCDCD Object dump complete. The information displayed is: the memory allocation number (142), block type (normal), the hexadecimal memory location (0x0079A948), and the size of the block (25 bytes long). Rewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.

#define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> #include <string> void memLeak() { int *p = new int;


char * string1 = new char[20]; char * string2 = new char[25]; strcpy(string1, "Sheldon");

string2=string1; delete p; }

int main(intargc, char* argv[]) { memLeak(); _CrtDumpMemoryLeaks();

return 0; } C++ code with no memory leaks: Screenshot: ==============================================

GSP 215 Week 5 iLabMemory


FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 5 iLab Week 5 Lab—Memory TCO 6—Given the fundamental role of processes in organizing a computer's flow of execution, be able to explain how multitasking/multiprocessing works, including what constitutes a context switch. TCO 7—Given that performance of a game is dominated by the speed of various parts of the memory system, understand algorithms used to manage memory on a computer. Scenario In this week’s lab, you will create a memory viewer using a combination of C and C++ to create an interactive tool for visualizing memory.

This lab is based on this video series by Professor Michael Vaganov: https://www.youtube.com/playlist?list=PLL2gGK4F_vGcPgzzPPJMdQ S9uW3DO_u_F


Please watch the video series, which will walk you through creating a memory viewer step by step. Each video builds on the successive one until you have an interesting memory viewer at the end. The program starts with Hello World in C++. #include <iostream> int main() { std::cout<<"Hello world"<<std::endl; return 0; } Work through the code with the author. Submit your code and screenshot of the final project to the Dropbox.

==============================================

GSP 215 Week 6 Homework Virtual Memory

FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 6 Homework Assignment


Week 6 Homework—Virtual Memory This week's homework problems will be completed in the book. Complete problems 9.12 and 9.13 below. Review Section 9.6.4 as a guide. Problem 9.11 is done below to help you. 9.11. For the given virtual address, indicate the TLB entry accessed, the physical address, and the cache byte value returned. Indicate whether the TLB misses, whether a page fault occurs, and whether a cache miss occurs. If there is a cache miss, enter – for cache byte returned. If there is a page fault, enter - for PPN, and leave parts C and D blank. You will need to use the tables on page 796 for PPN translation (page table b).

==============================================

GSP 215 Week 6 iLabVirtual Memory

FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 6 iLab Week 6 Lab—Virtual Memory


TCO 9—Given the need to support the runtime creation of varying quantities of data objects, learn how dynamic memory allocation can provide this capability in a very efficient way. TCO 8—Given the need to understand virtual memory, describe how memory allocation and paging are used to give a computer program access to more memory than physically available. Scenario In this week’s lab, you will override the new and delete operators for an implementation of linked list. Rubric Point distribution for this activity Lab Activity Document Points possible Points received Code and screenshot 40 Total Points 40 Generally, the default implementation of new and delete is sufficient for a given program. At times, you may want to specialize memory allocation for advanced tasks. You may want to allocate instances of a certain class from a particular memory pool, implement your own garbage collector, or caching. We will override the new and delete operator in this lab. When overriding these operators, both need to be overridden. The new operator allocates memory and creates an object. The delete operator deallocates memory.


We will be implementing a linked list class and overloading the new and delete operator. We can improve the speed of allocating new nodes by keeping a list of deleted nodes and reusing the memory when new nodes are allocated. The code for the linked list is below. You may also use your own implementation of linked list. The overloaded new operator will check a freelist to recycle a node before going to the heap and getting one that way. The delete operator will add the node to the freelist. Hint: Use the following in the Node class. void * operator new(size_t); void operator delete(void*); static void printFreelist(); After the class Node definition, be sure to set the freelist to NULL. Node* Node::freelist=NULL;

Implement Node::printFreelist() as well, and in the Main, include calls to Node::printFreelist(); to see the nodes in the free list. Original C++ Code: #include <iostream> using namespace std;


==============================================

GSP 215 Week 7 Homework Networking Commands

FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 7 Homework Assignment Week 7 Homework—Networking Commands This week's homework will focus on basic networking commands. Display IP configuration settings. 1. Open a Windows CLI (Start->run type in cmd and press enter) 2. The ipconfig command is used to view a computer's IP address. When your system is resolving the DNS addresses incorrectly, flushing the DNS using ipconfig –flushdns is a helpful command. To release and renew an IP address, use ipconfig – release and ipconfig –renew. What does subnet mask mean? What does default gateway mean? 3. Ping is used to verify connectivity to a network. Ping a web address of your choice, and press control + c to stop it. Paste the screenshot below.


4. Run traceroute on a website address of your choice (control + c to stop). Example: tracert devry.edu 5. Nslookup is helpful to know if the DNS is working correctly. Run nslookup against a hostname to see if the name is resolved. Example: nslookupwww.cnn.com 6. The netstat command has many options and gives a lot of information about your network. The –a option will show you the open ports on your computer. 7. If you have a Windows machine, go to the control panel on your computer. Then pick network and sharing center. Under view your active networks, you will see a link next to connections (in the above picture it is wired). Click on the link you see next to connections, then click on properties. Select Internet protocol version 4 (TCP/IPv4), and click properties. Note that changing these settings may disconnect you, so click cancel rather than OK. • To obtain IP settings automatically, click obtain an IP address automatically, and then click OK. • To specify an IP address, click use the following IP address, and then in the IP address, subnet mask, and default gateway boxes, type the IP address settings. Take a screenshot of your settings. Why would you choose ==============================================


GSP 215 Week 7 iLabNetworking and a Tiny Web Server

FOR MORE CLASSES VISIT www.gsp215rank.com GSP 215 Week 7 iLab Week 7 Lab—Networking and a Tiny Web Server TCO 1—Given a computing environment with multiple operating systems, demonstrate the ability to use the command line interface in Windows and Linux, and compile and run a program using the command line. TCO 10—Given the importance of networking in game design, explain how computers are connected to a network, and summarize basic networking fundamentals, terminologies, protocols, and devices. Scenario In this week's lab, we will create two C programs to use with networking commands. The first program will read a domain name or dotteddecimal address from the command line and display the corresponding host entry. The second program will be a tiny web server used on localhost. Part A:


In this lab, we will explore DNS mapping by creating a file named hostinfo.c. This program will read a domain name or dotted-decimal address from the command line and display the corresponding host entry. Local host will always map to 127.0.0.2. Enter the following C code into notepad. Save the file in the cygwin\home\username folder on your computer (ie: C:\cygwin64\home\gina) as hostinfo.c. Open Cygwin, and compile the program: gcchostinfo.c â&#x20AC;&#x201C;o hostinfo. #include <stdlib.h> #include <stdio.h> #include <arpa/inet.h> #include <netdb.h> Run the program with the following domain names, and note the results. Also, choose some of your own. Part B: Read pages 919-927 in the book. We will be developing the tiny web server listed in the book. This web server supports the GET method. It will look for an HTML file in the current directory and will display the web page in a web browser. Please study and review the code to understand what it is doing. Feel free to extend the code as well. Copy the C code below into notepad. Save the file in the cygwin\home\username folder on your computer (i.e., C:\cygwin64\home\gina) as tiny.c. Compile the program: gcctiny.c â&#x20AC;&#x201C;o tiny. , at a cygwin prompt, type ./tiny 10000.


This will start the web server listening at port 10000. Open your web browser, and type the following in the address bar: http://localhost:10000/home.html. This will open your website using your own tiny web server. To stop your tiny web server, press control + c in cygwin. Include a screenshot below of your web page working in a browser. C Code: //Tiny web server code #include <stdlib.h> #include <stdio.h> ==============================================

GSP 215 RANK Experience Tradition / gsp215rank.com  

__This course provides a wide range of university students-centered service

GSP 215 RANK Experience Tradition / gsp215rank.com  

__This course provides a wide range of university students-centered service

Advertisement