CompOrg Fall 2003

C program to display memory in various formats

Due Date: 9/29 (by 11:00PM)
Submit using WebCT: assignment HW2

Late Penalty: 10% per day. No submissions will be accepted after 11:00PM on October 6th

You may not share code with anyone else, you must work alone!
Feel free to discuss the project with anyone, just make sure you don't share code in any form! You are expected to write all the code you submit (do not submit code you find on the WWW!!!).

Assignment

This assignment involves the creation of a C program which can be compiled and run under FreeBSD, we will test your code using gcc as the compiler.

You are to write a program that is capable of displaying the values of individual bytes in memory using various representations (hex, decimal, binary). Command line parameters will be used to tell your program what address to start displaying, and what format should be used to display each memory location. Initially your program should display the address (as 32 bit hex) followed by the value of that memory location. Each time the user presses the Enter key, your program should advance to the next memory location and display the address and value (using the same format). If the user presses 'q' your program should quit.

Your submission must include a single C file named "hw2.c", and it must be written to work with the command line parameters described below. We will use an automated system to run your program, so if you don't follow the instructions below we won't be able to grade your program!

We will compile your program with the command line "gcc -o hw2 hw2.c" (the resulting executable program will be named hw2). The command line parameters are listed below:

  1. The first command line parameter (argv[1]) will indicate the starting address your program should use, this will be provided in hexadecimal.

  2. The second command line parameter will be a single character that indicates what representation should be used to display the value of memory locations. The only possible characters used will be 'b' (for binary), 'x' (for hex) and 'd' for decimal (unsigned 8 bit integer).

For example, the command line ./hw2 AB3240 x means "show the value of memory starting at location 0x00AB3240 as 2 hex digits."

For the decimal format, the values must be in the range 0 to 255 (so treat memory as an unsigned 8 bit integer).

For hex format, the values must be exactly 2 hex digits (never only one digit, and never more than 2)!

For binary format, the values must be displayed by exactly 8 characters (each either a '1' or '0'). Note that there is not "binary" format provided by printf - you need to write code to output '1's and '0's yourself.

Examples

A few examples of the possible output for various command line parameter values are shown below. Note that the value of any specific memory location will likely be different for you! '>' is the shell prompt.

In the examples below, the user is pressing the Enter key 8 times, then pressing 'q' and hitting Enter (the 'q' in each example is from the user, not the program).

Printing in hex
> ./hw2 8048617 x
08048617: c4
08048618: 10
08048619: eb
0804861a: 45
0804861b: 90
0804861c: 83
0804861d: c4
0804861e: fc
0804861f: 83q
>

Printing as 8 bit unsigned int
> ./hw2 8048617 d
08048617: 196
08048618: 16
08048619: 235
0804861a: 69
0804861b: 144
0804861c: 131
0804861d: 196
0804861e: 252
0804861f: 131q
>
  

Printing in binary
>  ./hw2 8048617 b
08048617: 11000100
08048618: 00010000
08048619: 11101011
0804861a: 01000101
0804861b: 10010000
0804861c: 10000011
0804861d: 11000100
0804861e: 11111100
0804861f: 10000011q
>
  
How to submit

Submission of your homework is done using WebCT (webct.rpi.edu). Once you log in to WebCT and access the CompOrg site, you should click on assignments, then select HW2. Upload your hw2.c file to webct. Make sure your browser is supported before you attempt to upload a file (there is a link to "Check Browser"). Dave will demonstrate submission using WebCT in class.

For this assignment, the file hw2.c is all you need to submit. For future assignments you will need to submit multiple files...

Don't send compiled code, only send your C program!

Multiple Submissions: You can resubmit as many times as you want, WebCTwill make sure we get the last file you submit.

Grading

Grades will be determined by testing your program with various valid command lines (we will not test with invalid options). We will not deduct points if your program SEGV's when we give it an invalid address (it's up to us to provide good addresses).

You get up to 25% for supporting each of the 3 formats (hex, decimal and binary) correctly. You get 25% for allowing the user to sequence through as many memory locations as desired (for handling user input and quitting only when 'q' is pressed).

HINTS: