Docsity

CSC 2400, Fall 2008: Bit Manipulation Workshop 1, Assignments of Operating Systems

Toggle sidebar
bg1
CSC 2400, Fall 2008
Workshop 1: Manipulating Bits
Assigned: Thur. Sept. 4, Due: Thur. Sept. 18, 11:59PM
Dr. Tom Way
Introduction
The purpose of this assignment is to become more familiar with bit-level representations and manipulations,
and ultimately gain a deeper understanding of how operations are performed and data is handled in the
system. You’ll do this by solving a series of programming “puzzles.” Many of these puzzles are quite
artificial, but you’ll find yourself thinking much more about bits in working your way through them.
Logistics
You may work in a group of up to two people in solving theproblems for this assignment. The only “hand-
in” will be electronic. Any clarifications and revisions to the assignment will be posted on the course Web
page.
Hand Out Instructions
Step 1. Make a directory called datalab in your home directory (mkdir datalab).
Step 2. Copy Makefile,btest.c,bits.c and countops.pl from /mnt/a/tway/datalab to
your own datalab directory using the cp command. The only file you will modify is bits.c.
Note: make sure that you login to a machine other than csgate to perform your work (i.e., degas, cezanne,
tanner, picasso, rodin, cassatt, gauguin, or matisse).
Step 3. Use the command make to compile the project, then type btest to run it. Repeat this step each
time you make a modification to your bits.c file and want to test it.
Step 4. In bits.c, edit the team members character string variable to include the name, or names, of
your programming team members.
The bits.c file also contains a skeleton for each of the 16 programming puzzles. Your assignment is to
complete each function skeleton using only straightline code (i.e., no loops or conditionals) and a limited
number of C arithmetic and logical operators. Specifically, you are only allowed to use the following eight
operators:
!˜&ˆ|+<<>>
1
pf3
pf4

Partial preview of the text

Download CSC 2400, Fall 2008: Bit Manipulation Workshop 1 and more Assignments Operating Systems in PDF only on Docsity!

CSC 2400, Fall 2008

Workshop 1: Manipulating Bits

Assigned: Thur. Sept. 4, Due: Thur. Sept. 18, 11:59PM

Dr. Tom Way

Introduction

The purpose of this assignment is to become more familiar with bit-level representations and manipulations, and ultimately gain a deeper understanding of how operations are performed and data is handled in the system. You’ll do this by solving a series of programming “puzzles.” Many of these puzzles are quite artificial, but you’ll find yourself thinking much more about bits in working your way through them.

Logistics

You may work in a group of up to two people in solving the problems for this assignment. The only “hand- in” will be electronic. Any clarifications and revisions to the assignment will be posted on the course Web page.

Hand Out Instructions

Step 1. Make a directory called datalab in your home directory (mkdir datalab).

Step 2. Copy Makefile, btest.c, bits.c and countops.pl from /mnt/a/tway/datalab to your own datalab directory using the cp command. The only file you will modify is bits.c.

Note: make sure that you login to a machine other than csgate to perform your work (i.e., degas, cezanne, tanner, picasso, rodin, cassatt, gauguin, or matisse).

Step 3. Use the command make to compile the project, then type btest to run it. Repeat this step each time you make a modification to your bits.c file and want to test it.

Step 4. In bits.c, edit the team members character string variable to include the name, or names, of your programming team members.

The bits.c file also contains a skeleton for each of the 16 programming puzzles. Your assignment is to complete each function skeleton using only straightline code (i.e., no loops or conditionals) and a limited number of C arithmetic and logical operators. Specifically, you are only allowed to use the following eight operators:

Name Description Rating Max Ops bitNor(x,y) ˜(x|y) using only & and ˜ 1 8 bitXor(x,y) ˆ using only & and ˜ 2 14 isNotEqual(x,y) x != y? 2 6 getByte(x,n) Extract byte n from x 2 6 copyLSB(x) Set all bits to LSB of x 2 5 logicalShift(x,n) Logical right shift x by n 3 16 bitCount(x) Count number of 1’s in x 4 40 bang(x) Compute !x without using! operator 4 12 leastBitPos(x) Mark least significant 1 bit 4 30

Table 1: Bit-Level Manipulation Functions.

A few of the functions further restrict this list. Also, you are not allowed to use any constants longer than 8 bits. See the comments in bits.c for detailed rules and a discussion of the desired coding style.

Evaluation

Your code will be compiled with GCC and run and tested on one of the class machines. Your score will be computed out of a maximum of 80 points based on the following distribution:

42 Correctness of code running on one of the class machines.

32 Performance of code, based on number of operators used in each function.

6 Style points, based on your instructor’s subjective evaluation of the quality of your solutions and your comments.

The 16 puzzles you must solve have been given a difficulty rating between 1 and 4, such that their weighted sum totals to 42. We will evaluate your functions using the test arguments in btest.c. You will get full credit for a puzzle if it passes all of the tests performed by btest.c, half credit if it fails one test, and no credit otherwise.

Regarding performance, our main concern at this point in the course is that you can get the right answer. However, we want to instill in you a sense of keeping things as short and simple as you can. Furthermore, some of the puzzles can be solved by brute force, but we want you to be more clever. Thus, for each function we’ve established a maximum number of operators that you are allowed to use for each function. This limit is very generous and is designed only to catch egregiously inefficient solutions. You will receive two points for each function that satisfies the operator limit.

Finally, we’ve reserved 6 points for a subjective evaluation of the style of your solutions and your com- menting. Your solutions should be as clean and straightforward as possible. Your comments should be informative, but they need not be extensive.

Advice

You are welcome to do your code development using any system or compiler you choose. Just make sure that the version you turn in compiles and runs correctly on our class machines. If it doesn’t compile, we can’t grade it.

The countops.pl program is very basic perl program that counts the ops used in your file, and also looks for the use of any illegal operators or constants that are too large. Run it from the command line by typing tt countops.pl bits.c.

Hand In Instructions

  • Make sure you have included your identifying information in your file bits.c.
  • Remove any extraneous print statements.
  • To hand in your bits.c file when you are done, simply make sure it is in the datalab directory in your home directory, and then send email to Dr. Way. Make sure to mention in your email the names of all members of your team so that proper credit can be given.

Note: This lab is based heavily on a similar lab prepared by the authors of our textbook.