CS 3330: Lab 1: Datalab

This page does not represent the most current semester of this course; it is present merely as an archive.

The purpose of this assignment is to become more familiar with bit-level representations of integers and floating point numbers. 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.

Have trouble getting it to work on your machine? Try the following:

    linux> sudo apt-get install libc6-dev-i386 gcc-multilib 

Logistics

Follow the instructions of your lab TAs. In general, you may work together however you wish as long as they do not say otherwise.

After this lab is over you will be given a homework assignment which is much like the lab (the same structure, but with different puzzles). The homework assignment you must do individually (no group work), so if you do work with others during lab make sure you understand everything your group does.

Logging In

You should have received an email with your lab unix login in the past 8 days. If you think you did not, check your spam folders.

There is a problem with the password changing program yppasswd in the current linux build in the labs. To work around it,

  1. If the machine is booted in windows, restart and pick ubuntu from the bootloader screen.
  2. log in with the password you got in your email
  3. open a terminal (e.g., Alt-F2 → gnome-terminal → Enter)
  4. type ssh labunix04.cs.virginia.edu
  5. if ssh asks for a password, use the one you got in your email again.
  6. type yppasswd and follow the instructions
  7. type either Ctrl-D or exit to exit labunix and return to your computer.

Handout Instructions

Start by copying datalab-handout.tar to a (protected) directory on a Linux machine in which you plan to do your work. Then give the command

linux> tar xvf datalab-handout.tar

(note: the linux> represents the command prompt; do not type it when entering commands)

This will cause a number of files to be unpacked in the directory. The only file you will be modifying and turning in is bits.c.

Next make sure it works. Do

linux> cd datalab-handout
linux> make

If that give you an error about inability to find gcc or pow then they still haven't fixed a bug with the lab linux boxes. Try

linux> sed -i 's/gcc/gcc-4.8/g' Makefile

as a workaround, then try make again.

The bits.c file contains a skeleton for each of the programming puzzles. Your assignment is to complete each function skeleton using only straightline code for the integer puzzles (i.e., no loops or conditionals) and a limited number of C arithmetic and logical operators. The exact set of operators varies by puzzle.

The Puzzles

Each puzzle is describes in comments in the bits.c file. Read the comments. All of them.

Evaluation

This lab is designed to look like the homework that will follow it. However, lab participation is more important than lab success, and lab work will be graded generously. This section describes how the homework will be graded.

Correctness points.
Each puzzle you must solve has been given a difficulty rating between 1 and 4 and is worth that many points. We will evaluate your functions using the perl driver.pl program, which is described in the next section. You will get full credit for a puzzle if it passes all of the tests performed by driver.pl, and no credit otherwise.
Performance points.
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 correct function that satisfies the operator limit.

Autograding your work

We have included some autograding tools in the handout directory — btest, dlc, and driver.pl — to help you check the correctness of your work.

driver.pl

This is a driver program that uses btest and dlc to compute the correctness and performance points for your solution. It takes no arguments:

linux> ./driver.pl

Your instructors will use driver.pl to evaluate your solution. If it doesn't work for you, it won't work for us either.

btest

This program checks the functional correctness of the functions in bits.c. To build and use it, either use driver.pl or type the following two commands:

linux> make
linux> ./btest

Notice that you must rebuild btest each time you modify your bits.c file.

You’ll find it helpful to work through the functions one at a time, testing each one as you go. You can use the -f flag to instruct btest to test only a single function:

linux> ./btest -f bitXor

You can feed it specific function arguments using the option flags -1, -2, and -3:

linux> ./btest -f bitXor -1 7 -2 0xf

Check the file README for documentation on running the btest program.

dlc

This is a modified version of an ANSI C compiler from the MIT CILK group that you can use to check for compliance with the coding rules for each puzzle. The typical usage is either to use driver.pl or to invoke it directly:

linux> ./dlc bits.c

The program runs silently unless it detects a problem, such as an illegal operator, too many operators, or non-straightline code in the integer puzzles. Running with the -e switch:

linux> ./dlc -e bits.c  

causes dlc to print counts of the number of operators used by each function. Type ./dlc -help for a list of command line options.

Advice

Handin Instructions

You should turn in your finished bits.c on the submissions page. Remember, the lab is graded on effort so when time ends you are welcome to declare yourself finished and submit what you have.

Remember to replace <Please put your name and userid here> with your name and computing id. If you worked with others or consulted sources other than the course website and textbook, list those there too. For example,

/* 
 * CS:APP Data Lab 
 * 
 * Luther Tychonievich (lat7h)
 * Used http://dx.doi.org/10.1109%2FIEEESTD.2008.4610935 
 * Worked with Mystery Theater (mst3k)
 * Tom Jefferson (tj1a) helped me understand what ~ does

Even if you work as a pair on developing just one bits.c, each partner should submit the file with their own name as the author and the others as collaborators.

The “Beat the Prof” Contest

For fun, we’re offering an optional “Beat the Prof” contest that allows you to compete with other students and the instructor to develop the most efficient puzzles. The goal is to solve each Data Lab puzzle using the fewest number of operators. Students who match or beat the instructor’s operator count for each puzzle are winners!

To submit your entry to the contest, type:

linux> ./driver.pl -u "Your Nickname"

Nicknames are limited to 35 characters and can contain alphanumerics, apostrophes, commas, periods, dashes, underscores, and ampersands. You can submit as often as you like. Your most recent submission will appear on a real-time scoreboard, identified only by your nickname. You can view the scoreboard by pointing your browser at

http://wilkes.cs.virginia.edu:8080

Wilkes is just some computer we have, and it might not be up all the time. If you can't see it, try again an hour later.

Note that you'll still need to submit to the submissions page even if you also submit to the “Beat the Prof” contest.

Copyright © 2015 by Luther Tychonievich. All rights reserved.
Last updated 2015-01-16 12:10 -0500