Lab 2: Implementing memdump

In this lab you will write a program to display the content in hexadecimal and ascii of a section of memory.

Step 1

Download the file lab2-src.tar.Z (lab2-src) and uncompress it and untar it. This file will serve as base for the code you will write in this lab.
 

uncompress lab2-src.tar.Z
tar -xvf lab2-src.tar

Step 2

In the file memdump.cpp implement the procedure memDump(char * ptr, int size) that prints to stdout the memory content in hexadecimal and in ascii starting at location "ptr" up to size bytes in the following format for each line:

XXXXXXXX: YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY <AAAAAAAAAAAAAAAA>

where XXXXXXXX is the memory address, YYYYYYYY is the data in hecadecimal. Each pair of YY represents a byte. The leftmost YY is the one that appears in first in memory. <AAAAAAAAAAAAAAAA> is the same data in ascii format. Print "." for the non-printable characters (ch < 32 || c >127). In XXXXXXXX pad with 0s to complete 8 bharacters.

3. Compile and run the memdumptest program and answer the following questions. Include the answers to these questions in a file answers.html. You will print this file and turn it in in the next PSO.

Q1. Copy and paste the output of memdumptest in answers.html.

Q2. Verify that the binary representation of ithe variable int1 in the memory dump is 234 by converting from hexadecimal to binary representation and then to decimal. Show your steps in answers.html.

Q3. Verify that the binary representation of the variable int2 in the memory dump is -5 by converting from hexadecimal to binary representation and then obtaining the 2 complement and then coverting to decimal. Show your steps in answers.html.

Q4. Verify that the binary representation of the variable double1 in the memory dump is 4. Do that by finding out the representation of double in the Sparc using Google (search for "sparc double representation ieee). Show your steps in answers.html.

Q5. Verify that the binary representation of the variable double2 in the memory dump is 4. Do that by finding out the representation of double in the Sparc using Google (search for "sparc double representation ieee). Show your steps in answers.html.


5. Write a program "endian" that prints "Big-Endian" if the machine the computer you are running the program on is big-endian or "Little-Endian" if it is little-endian. Name your program endian.cpp and modify your Makefile to be able to build it. Search in the web to see what little/big-endian is. Hint: Assign an arbitrary  number to an int variable and then try to see the int variable as an array of characters, Then see what the first byte of the integer contains.
Test your program in mentor (SPARC) and ini one of the lab machines (x86).

Note:
The lab instructors will read your code and will make observations regarding to:
    Clarity
    Refactoring (Removing redundant code)
    Comments
20% of the grade in your project will depend on it.

Turning in this lab

You will turnin electronically the following:
  1. Your implementation of memdump
  2. Your implementation of endian
  3. The answers all the questions.
You will place your file answers.html in the directory lab2-src/ and also place in there all the files used in your implementation.

Login to one of the lab machines and type:

turnin -c cs250 -p lab2 lab2-src
To verify your submission type "turnin  -c cs250 -p lab2 -v"

Submit your lab before Thursday January 31st at 11:59pm.