New version page

UConn CSE 2102 - Lab #1

Documents in this Course
Load more
Upgrade to remove ads

This preview shows page 1 out of 2 pages.

View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

CSE 3100 Systems Programming Fall 2018Lab #1Welcome to Lab 1! This lab assignment is due 24 hours after your lab session starts. For example, if your labsession starts at 8am on Friday, the assignment is due at 8am on Saturday. If changes to the due date need to be made,they will be announced on HuskyCT or Piazza.The lab has three parts. The first two parts require you to modify the provided skeleton code and the third toupdate the provided Makefile. Read each question carefully before beginning work. Start by executing git pullinside your Git repository on the virtual machine. This will create a directory called lab1 which includes skeletoncode for firs two programs. This code includes a function print_bits() that takes an integer as its only argumentand prints this integer in four formats: hexadecimal, decimal when bits are interpreted as a signed integer, decimalwhen bits are interpreted as an unsigned integer, and binary (bits).Do all your work inside the lab1 directory. Remember to add, commit, and push when you complete yourwork. Add ONLY changes to xorbit.c, reversebytes.c and Makefile to the git repo. Do not add .o files orexecutables.Part 1. xorbit is a program that initializes an integer n to zero then repeats the following operations:1) Read from the standard input an integer pos between 0 and 31,2) Flip the bit at position from the standard input in n, and3) Call print_bits() to print n’s bits.The program terminates when there is an error or the end of file (EOF) is detected at the standard input (when theuser presses Ctrl-D).The skeleton code provided already performs Steps 1 and 3. Your job is to complete Step 2, which can be doneby generating a mask with a single 1 at the correct position and xor-ing the mask with n. Note that bit 0 is the leastsignificant (rightmost) bit and bit 31 is the most significant (leftmost) bit in an int. You can assume integers read fromthe standard input are between 0 and 31 (inclusively). You are encouraged to examine the behavior of the programif other integers are entered. An example session with the modified program is shown below. In this example, 0, 1,and 31 are the integers entered by the user.$ ./xorbithex:00000000 signed:0 unsigned:0 bits:000000000000000000000000000000000hex:00000001 signed:1 unsigned:1 bits:000000000000000000000000000000011hex:00000003 signed:3 unsigned:3 bits:0000000000000000000000000000001131hex:80000003 signed:-2147483645 unsigned:2147483651 bits:100000000000000000000000000000110hex:80000002 signed:-2147483646 unsigned:2147483650 bits:100000000000000000000000000000101hex:80000000 signed:-2147483648 unsigned:2147483648 bits:10000000000000000000000000000000Part 2. reversebytes is a program that repeats the following operations:1) Read an integer n from the standard input,2) Reverse the order of four bytes of n and save the reversed bytes in integer n1, and3) Call print_bits() to print out n and n1.1The skeleton code provided already performs Steps 1 and 3. Your job is to complete Step 2. For each byte inn, you must get the 8 bits from n, shift them to the correct position, and bitwise “or” the shifted bits with the bitsalready in n1. Of course, n1 is set to 0 initially. You can assume that integers have four bytes. An example sessionwith the modified program is shown below. In this example, 1234567 and 19088743 are the user input.$ ./reversebytes1234567hex:0012D687 signed:1234567 unsigned:1234567 bits:00000000000100101101011010000111hex:87D61200 signed:-2016013824 unsigned:2278953472 bits:1000011111010110000100100000000019088743hex:01234567 signed:19088743 unsigned:19088743 bits:00000001001000110100010101100111hex:67452301 signed:1732584193 unsigned:1732584193 bits:01100111010001010010001100000001Part 3. An example of Makefile is provided. With this file in place, running make compiles xorbit.c to generatexorbit if the executable does not exist. If both xorbit.c and xorbit exist, running make will re-compile xorbit.cif it has a more recent modification timestamp than xorbit. The Makefile also has a clean rule that removes allobject files and the xorbit executable – this can be used to quickly clean up your assignment folder before makingyour submission with Git.You must change the existing rules and add new rules to Makefile to support in a similar way the buildingof revserbytes. The default rule all should update both xorbit and reversebytes executables if necessary.Similarly, the clean rule needs to be revised to remove both executables.Your lab TA will provide an introduction to Makefiles at the beginning of the lab. The full documentation forGNU Make is available

View Full Document
Download Lab #1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...

Join to view Lab #1 and access 3M+ class-specific study document.

We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab #1 2 2 and access 3M+ class-specific study document.


By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?