Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the program in C please! Introduction This assignment investigates the structure of computer memory and the data stored there. An assembly programming class will

Write the program in C please!

Introduction

This assignment investigates the structure of computer memory and the data stored there. An assembly programming class will study the architecture of memory in more depth. Nevertheless, this assignment will refresh your knowledge about the subject or even provide you with a new perspective regarding the subject of memory.

Requirements

Make two functions for showing the contents of memory. They have names like showquadwords and showdoublewords, but you may give them other names. The two functions are describe later in this document. Also, make a main function whose purpose is to test these two functions.

The quadword memory dump function

Create a C function that will display the contents of contiguous memory in quadword chunks. Two parameters are passed to this function: the starting address and the total number of bytes to be displayed. Both of these numbers are of type unsigned long. The function has return type void. [Some people call the output from this function a memory dump.]

Sample output from the quadword display function.

Offset Location in hex Location in Decimal Quadword String

00: 0x0000000001d86430 000000000030958640 0x4847464544434241 HGFEDCBA

08: 0x0000000001d86438 000000000030958648 0x2424242424240049 $$$$$$ I

16: 0x0000000001d86440 000000000030958656 0x2424242424242424 $$$$$$$$

24: 0x0000000001d86448 000000000030958664 0x0000000000000024 $

For this discussion suppose the name of the function is show_memory_by_quadwords. Then the sample output above could have be generated by a call in main like the following one.

show_memory_by_quadwords(30958640l,26l);

Notice these facts. Literal integers followed by lower case l will be converted internally to type long. Also, the value 26 is not a multiple of quadwords, and therefore, it is rounded up to the next multiple of quadwords; in this sample rounding up to the next whole number of quadwords results in 32 bytes (4 whole quadwords) of memory to be outputted.

The last column is labeled String. It could be labeled Chars. That column contains the textual representation of the character whose hex value is in the column label Quadword. Look at the example below. You have to read the quadword from right to left. The first byte of the quadword is 41, the second byte is 42, the third byte is 43, etc. The ascii character for 41 is A. That is why A appears on the right side of the String column.

Offset Location in hex Location in Decimal Quadword String

00: 0x0000000001d86430 000000000030958640 0x4847464544434241 HGFEDCBA

Some ascii value do not print anything. Specifically ascii values less than 32 decimal do not print. Therefore, when a non-printing ascii value appears in the quadword then its position in the string should be a space character. You make your program show a space in the String column whenever the Quadword value is less than 32.

Offset Location in hex Location in Decimal Quadword String

08: 0x0000000001d86438 000000000030958648 0x2424242424240049 $$$$$$ I

In the example above the ascii value 00 is replaced in the string by a space.

More examples of main calling the display quadword function

Suppose the main function declared these data variables:

int x = 15;

double * q = new malloc(12*sizeof(foat));

Then call the function can be called like this:

show_memory_by_quadwords(q,x);

It is possible that C language may insist that you cast the variables first like this:

show_memory_by_quadwords((unsigned long)q,(unsigned long)x);

You try it and discover which one works.

The doubleword memory dump function

Create a C function that will display the contents of contiguous memory in quadword chunks. Two parameters are passed to this function: the starting address and the total number of bytes to be displayed. Both of these numbers are of type unsigned long. The function has return type void

Sample output from the doubleword display function.

Offset Location in hex Location in Decimal Doubleword String

00: 0x0000000001d86430 000000000030958640 0x44434241 DCBA

04: 0x0000000001d86434 000000000030958644 0x48474645 HGFE

08: 0x0000000001d86438 000000000030958648 0x24240049 $$ I

12: 0x0000000001d8643c 000000000030958652 0x24242424 $$$$

16: 0x0000000001d86440 000000000030958656 0x24242424 $$$$

20: 0x0000000001d86444 000000000030958660 0x24242424 $$$$

24: 0x0000000001d86448 000000000030958664 0x00000024 $

The sample output was created by calling the function as in the following:

show_memory_by doublewords(30958640l,30l);

Again, notice that when you want a literal number like 30 to be treated as type long then you append a lower case l to the number: 30l.

Test the two functions (showquadwords and showdoublewords) in the same run.

In main declare variables; you choose good names for them.

length of char array

a char array with space allocated by malloc

length of double array

a double array with space allocated by malloc.

length of an int array

a int array with space allocated by malloc

The dialog of a sample execution goes like this:

Welcome to this Memory Display Program by Katherine Romanov [use your own name]

Please enter the length of the char array: 65

Thank you. A char array of length 65 was created.

Please enter char data of less than 65 chars: The big brown cow jumped over the moon while singing a popular song.

Thank you. Here is the string you entered:

The big brown cow jumped over the moon while singing a popular song.

Please enter the length of your array of doubles: 13

Thank you. An array with space for 13 doubles has been created.

Please enter data of type double but no more than 13 such values. Terminate with Cntl+D.

5.4

-8.0

6.2

-10.1

3.3

7.4

9.0

1.0

Thank you. The data you entered are:

5.4 -8.0 6.2 -10.1 3.3 7.4 9.0 1.0

Please enter the length of your array of ints: 8

Thank you. An array with space for 8 ints has been created.

Please enter int data but no more than 8 such values. Terminate with Cntl+D.

7

3

19

6

37

Thank you. The data you entered are:

7 3 19 6 37

Now call the showquadwords function to dump the memory of the stack area.

[Memory dump appears here. It has the quadword format shown on an earlier page.]

Now call the showquadwords function to dump the memory of the heap where the array of doubles is stored.

[Memory dump appears here. It has the quadword format shown on an earlier page.]

Now call the showquadwords function to dump the memory of the heap where the array of char is stored.

[Memory dump appears here. It has the quadword format shown on an earlier page.]

Call the showquadwords function to dump the memory of the heap where the array of ints is stored.

Now call the showdoublewords function to dump the memory of the stack area.

[Memory dump appears here. It has the doubleword format shown on an earlier page.]

Now call the showdoublewords function to dump the memory of the heap where the array of doubles is stored.

[Memory dump appears here. It has the doubleword format shown on an earlier page.]

Now call the showdoublewords function to dump the memory of the heap where the array of char is stored.

[Memory dump appears here. It has the doubleword format shown on an earlier page.]

Call the showdoublewords function to dump the memory of the heap where the array of ints is stored.

[Memory dump appears here. It has the doubleword format shown on an earlier page.]

That is the end of showing memory.

The three arrays will now be de-allocated. That will release space in the heap.

Enjoy your programming. Bye.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago