Project Data: Manipulating Bits

Similar documents
CS 2505 Fall 2013 Data Lab: Manipulating Bits Assigned: November 20 Due: Friday December 13, 11:59PM Ends: Friday December 13, 11:59PM

CS 356, Fall 2018 Data Lab (Part 1): Manipulating Bits Due: Wednesday, Sep. 5, 11:59PM

BIL220, Spring 2012 Data Lab: Manipulating Bits Assigned: Feb. 23, Due: Wed., Mar. 8, 23:59PM

Data Lab: Manipulating Bits

CS 356, Fall 2018 Data Lab (Part 2): Manipulating Bits Due: Mon, Sep. 17, 11:59PM

MCS-284, Fall 2015 Data Lab: Manipulating Bits Assigned: Sept. 22, Due: Tues., Sept. 29, 11:59PM

CS 2505 Fall 2018 Data Lab: Data and Bitwise Operations Assigned: November 1 Due: Friday November 30, 23:59 Ends: Friday November 30, 23:59

CS-281, Spring 2011 Data Lab: Manipulating Bits Assigned: Jan. 17, Due: Mon., Jan. 31, 11:59PM

Data Lab: Manipulating Bits

ECEn 424 Data Lab: Manipulating Bits

EECS 213, Spring 2013 Data Lab: Manipulating Bits

CMSC 201, Fall 2014 Data Lab: Manipulating Bits Assigned: Sept. 03, Due: Wed., Sept. 17, 11:59PM

15-213, Spring 2008 Lab Assignment L1: Manipulating Bits Assigned: Jan. 15, Due: Wed., Jan. 30, 11:59PM

CS 105 Lab 1: Manipulating Bits

CS33 Project Gear Up. Data

CMSC 311 Spring 2010 Lab 1: Bit Slinging

FALL 2017 CSCI 304 LAB2 (Due on October-10, 11:59:59pm)

CSC 2400: Bit Manipulation Assignment

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM

Lab 03 - x86-64: atoi

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

CS356: Discussion #2 Integer Operations. Marco Paolieri

Computer Organization & Systems Exam I Example Questions

Learning Objectives. A Meta Comment. Exercise 1. Contents. From CS61Wiki

15213 Recitation Section C

Beginning C Programming for Engineers

CS Prof J.P.Morrison

printf( Please enter another number: ); scanf( %d, &num2);

Exercise Session 2 Systems Programming and Computer Architecture

Project 5 - The Meta-Circular Evaluator

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

CSCI544, Fall 2016: Assignment 1

CSCI0330 Intro Computer Systems Doeppner. Maze. Due: Wednesday, September 20, 2017 at 11:59pm. 1 Introduction 1. 2 Assignment 1.

CS 429H, Spring 2012 Optimizing the Performance of a Pipelined Processor Assigned: March 26, Due: April 19, 11:59PM

Preview from Notesale.co.uk Page 6 of 52

CS 241 Data Organization using C

ANITA S SUPER AWESOME RECITATION SLIDES. 15/18-213: Introduction to Computer Systems Bit Logic and Floating Point, 27 January 2014 Anita Zhang

EECE.2160: ECE Application Programming

MCS-284, Fall 2018 Cache Lab: Understanding Cache Memories Assigned: Friday, 11/30 Due: Friday, 12/14, by midnight (via Moodle)

Chapter 2 THE STRUCTURE OF C LANGUAGE

Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon)

ICS(II), Fall 2017 Cache Lab: Understanding Cache Memories Assigned: Thursday, October 26, 2017 Due: Sunday, November 19, 2017, 11:59PM

CS 113: Introduction to

Programming Assignment #4 Arrays and Pointers

Lecture 13 Bit Operations

Chapter 12 Variables and Operators

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #03 The Programming Cycle

Bit Hacks Project 1. Last Updated: October 3, 2010

Welcome to... CS113: Introduction to C

ISA 563 : Fundamentals of Systems Programming

15-213/18-213/15-513, Spring 2018 C Programming Lab: Assessing Your C Programming Skills

Arithmetic and Bitwise Operations on Binary Data

Digital Design and Computer Architecture Harris and Harris, J. Spjut Elsevier, 2007

LAB A Translating Data to Binary

CS 241 Data Organization Binary

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

CSCI0330 Intro Computer Systems Doeppner. Maze. Due: Wednesday, September 19, 2018 at 11:59pm. 1 Introduction 1. 2 Assignment 1.

15-213/18-213/15-513, Fall 2017 C Programming Lab: Assessing Your C Programming Skills

C - Basics, Bitwise Operator. Zhaoguo Wang

Lecture Notes on Ints

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

IRIX is moving in the n32 direction, and n32 is now the default, but the toolchain still supports o32. When we started supporting native mode o32 was

Tips from the experts: How to waste a lot of time on this assignment

Programming Assignment III

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2013

Programming Project 4: COOL Code Generation

In case you didn t get it (or you were too lazy to check)

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

COMP 105 Homework: Type Systems

Project #1: Tracing, System Calls, and Processes

Lecture 17 Bit Operations

CSCI544, Fall 2016: Assignment 2

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

Full file at C How to Program, 6/e Multiple Choice Test Bank

Introduction to Computer Engineering (E114)

Lab 1: Setup 12:00 PM, Sep 10, 2017

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Floating Point. What can be represented in N bits? 0 to 2N-1. 9,349,398,989,787,762,244,859,087, x 1067

CS2630: Computer Organization Project 2, part 1 Register file and ALU for MIPS processor

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

CS 241 Data Organization. August 21, 2018

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Slide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto

CS50 Supersection (for those less comfortable)

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

Project 5 - The Meta-Circular Evaluator

Assignment 3: Binary numbers, data types and C Programs Due 11:59pm Monday 26th March 2018

AGENDA Binary Operations CS 3330 Samira Khan

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

The print queue was too long. The print queue is always too long shortly before assignments are due. Print your documentation

Chapter 1 Getting Started

Arithmetic and Bitwise Operations on Binary Data

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

CSE 12 Week Three Lecture One Tomorrow s discussion: Getting started on hw4

Important Project Dates

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Transcription:

CSCI0330 Intro Computer Systems Doeppner Project Data: Manipulating Bits Due: September 26, 2018 at 11:59pm 1 Introduction 1 2 Assignment 1 2.1 Collaboration 3 2.2 TA Hours 3 3 The Puzzles 3 3.1 Bit Manipulations 3 4 General Advice 4 5 Hints 4 6 Grading 5 6.1 Testing your implementation 6 6.1.1 btest 6 6.1.2 dpc 6 6.1.3 driver.pl 7 7 Handing In 7 1 Introduction You just bought a brand new operating system from IKEA (it was on discount) and realized it comes with some assembly required. You look inside the box and realize they also forgot to include some essential operators! Your task is to complete the operating system by piecing together the 9 essential functions using only the logical operators that came in the box. 2 Assignment For this assignment, you will solve a series of programming puzzles which will test your ability to take advantage of bit-level representations. To solve all of the puzzles, you will need to employ your knowledge of bit-level operations and two's complement representation. Set up the support code and skeleton for this project by running the script cs0330_install data from the command line. The script will create a directory called data/ in your home directory that contains the files needed for the assignment. 1

The bits.c file (inside the directory that you just installed) contains a skeleton for each of the programming puzzles. Your assignment is to complete each function skeleton (each puzzle), subject to certain restrictions. The other files contain support code --- you are welcome to look at it, but you won't need to for the assignment, and we ask that you not modify it. For all puzzles in this assignment, you must use only straightline code (i.e., no loops or conditionals) and a limited subset of C arithmetic and logical operators. For most puzzles, you are allowed to use only the following eight operators:! ~ & ^ + << >>. A few of the functions further restrict this list. Also, you may only use one-byte constants (between 0 and 255, inclusive (between hexadecimal numbers 0x00 and 0xff )). The Binary Operators: Symbol Name Description Example (in binary)! Logical NOT ~ Bitwise NOT Returns 1 if the binary number is 0, 0 otherwise.! 0000 = 1! 0110 = 0 Flips every bit in the binary number. ~ 0110 = 1001 & Bitwise AND Compares each bit in both numbers, and sets it to 1 if both bits are 1, 0 otherwise. 0110 & 0101 = 0100 ^ Bitwise XOR Compares each bit in both numbers, and sets it to 1 if bit are different, 0 otherwise. 0110 ^ 0101 = 0011 Bitwise OR Compares each bit in both numbers, and sets it to 1 if either bit is 1, 0 otherwise. 0110 0101 = 0111 + Bitwise Add Adds the two binary numbers. 0110 + 0101 = 1011 << Left Shift Shifts all bits a given number of places to the left. 0110 << 1 = 1100 0110 << 2 = 1000 >> Right Shift Shifts all bits a given number of places to the right. 0110 >> 1 = 0011 0110 >> 2 = 0001 See the comments in bits.c for detailed rules and a discussion of the desired coding style. Note that this assignment is not fully supported on Mac, because the dpc binary will not work properly. If you choose to work on this assignment with your personal computer, just make sure it runs on a department machine before you hand it in! 2

2.1 Collaboration The nature of this assignment is quite different from the others in this course; consequently, the normal CS0330 collaboration policy will be modified for this assignment. For this assignment: You may not share any code for any part of this assignment with other students in the course. You may not discuss the solutions to any part of this assignment with other students, even at a high level. You may not assist other students with debugging, or look at any other student's code. Only you or a member of the course staff may examine your code. You may not search for solutions to these puzzles on the internet. 2.2 TA Hours The TAs are also limited in how they can help you. They are only allowed to give specific hints for each puzzle, and they are only allowed to help debug your code to make sure your syntax is correct. They may also talk about topics covered in lecture. 3 The Puzzles This section describes the puzzles that you will be solving in bits.c. For more information, see the comments in bits.c. You may also refer to the test functions in tests.c. These are used as reference functions to express the correct behavior of your functions (but they don't satisfy the coding rules for your functions). For each of the tables, the Rating field gives the number of points for the puzzle, and the Max Ops field gives the maximum number of operators you are allowed to use to implement each function. 3.1 Bit Manipulations Table 1 describes a set of functions that manipulate and test sets of bits. Name Description Rating Max Ops bit_and(int x, int y) x&y using only ~ and 1 8 negate(int x) compute -x 2 5 is_equal(int x, int y) compute x == y 2 5 3

div_pwr_2(int x, int n) compute x/(2 n ) 2 15 conditional(int x, int y, int z) compute x?y:z 3 16 add_ok(int x, int y) check whether x + y will overflow 3 20 abs_val(int x) compute the absolute value of x 5 6 bang(int x) compute! x 5 12 least_bit_pos compute a mask that indicates the least significant bit Ex: 0110 -> 0010 4 6 4 General Advice Read Chapter 2 of the textbook and the lecture slides on data representation. The information in these resources will help greatly with many of the puzzles. Any time you spend reading these materials before beginning some of the puzzles will reduce time you spend poring over them later. We also have a Logical Equivalences guide under the Guides and Documents section that may be useful. If you get stuck, ask the TAs! Course staff members will try to point you in the right direction without giving away the answer. Use the provided data project checker (./dpc bits.c, described in section 6.1.2 ) to make sure that your code follows the rules for each of the puzzles. A consequence of using this checker is that you will not be able to include the <stdio.h> header file in your code. Doing so confuses dpc and results in non-intuitive error messages. You will still be able to use printf() in your bits.c file for debugging without including the <stdio.h> header (although gcc will print a warning that you can ignore). Remove all print statements before handing in. When in doubt as to whether you can use a given operator, you can test whether it is valid by using it in the function in question and running./driver.pl, which will tell you if you have invalid operations in your code. If you're still confused, you're of course more than welcome to email the TAs and ask. 5 Hints You are only allowed to declare constants that fit in one byte of data However, this does not mean that you may not use constants that don't fit in one byte of data. If you find 4

yourself needing a large constant, consider how you can generate such a value using only small constants and binary operators. int x = 1024 isn't ok because 1024 doesn't fit in a single byte. int x = 1 << 10 is fine because 1 and 10 both fit in a byte You will find bit masks invaluable in this assignment. A bit mask is an integer whose binary representation is intended to combine with another value using either & or to extract or set a particular bit or set of bits respectively. For example, to extract the fourth bit of an integer: int mask = 0x8; /* 1000 in binary */ int value = 0xc; /* 1100 in binary */ return mask & value; /* returns 0x8, indicating that the fourth bit of the "value" variable was set */ 6 Grading Your score will be computed out of a maximum of 100 points based on the following distribution: 54 Correctness points. 36 Performance points. 10 Style points. Correctness points. The 9 puzzles you must solve have been given a rating between 1 and 5. Each puzzle is worth 2 times its rating, and their weighted sum totals 54. We will evaluate your functions using the btest program, which is described in the next section. Barring extenuating circumstances, you will get full credit for a puzzle if it passes all of the tests performed by btest, 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. This limit is designed to catch inefficient solutions; a few of the problems require some clever thinking to satisfy the limit. You will receive four points for each correct function that satisfies the operator limit. Style points. Finally, we've reserved 10 points for a qualitative evaluation of the style of your solutions and your commenting. Your solutions should be as clean and straightforward as possible. Your comments should be informative, but they need not be extensive. 5

6.1 Testing your implementation We have included some autograding tools in the handout directory --- btest, dpc, and driver.pl --- to help you check the correctness of your work. 6.1.1 btest The btest program checks the functional correctness of the functions in bits.c. To build and use it, type the following two commands within the data/ directory: make btest./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:./btest -f bit_and You can feed it specific function arguments using the option flags -1, -2, and -3 :./btest -f bit_and -1 7-2 0xf Check the file README for documentation on running the btest program. 6.1.2 dpc The dpc binary 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:./dpc 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:./dpc -e bits.c causes dpc to print counts of the number of operators used by each function. Type./dpc -help for a list of command line options. Note that this compiler enforces a stricter form of C declarations than gcc does. In particular, any declaration in a given scope (what you enclose in curly braces) must appear before any statement that is not a declaration. For example, dpc will reject the following code: int foo(int x) { 6

} int a = x; a *= 3; /* Statement that is not a declaration */ int b = a; /* ERROR: Declaration not allowed here */ At one time, this was required by the official C language specification. Thankfully, the modern standard has been updated to no longer require this restriction. 6.1.3 driver.pl The driver.pl script uses btest and dpc to compute the correctness and performance points for your solution. It takes no arguments:./driver.pl driver.pl will be used to evaluate your solution. 7 Handing In Note: Before handing make sure you run the formatting script with the cs0330_reformat command. (i.e. cs0330_reformat bits.c ) To hand in your project, run the command: cs0330_handin data from your project working directory. If you wish to change your handin, you can do so by re-running the handin script. Only your most recent handin will be graded. Important note: If you have already handed in your assignment, but plan to hand in again after the TAs start grading at noon on Saturday, September 29th, you must run cs0330_grade_me_late data to inform us. You must run the script by noon on 9/29. If you run this script, you will get grades back later than other students. If you do not run this script, the TAs will proceed to grade whatever you have already handed in, and you will receive a grade report with the rest of the class that is based on the code you handed in before we started grading. If something changes, you can run the script with the --undo flag (before noon on 9/29) to tell us to grade you on-time and with the --info flag to check if you re currently on the list for late grading. These instructions apply to all projects unless otherwise stated on the handout. 7