CSC 373: Computer Systems I

Homework 1

Due by 11:50 am on Tuesday, January 14



Please write precise and concise answers.

Reading

Read Chapter 1 of BO* and Sections 1.1-4, 1.7-8, 2.1-2, 2.4-8, 2.10-12, 3.1-3, 3.5-7 of KR* as well as the lecture 1 notes on C programming.

*BO = Computer Systems by Bryant and O'Hallaron
*KR = The C Programming Language by Kernighan and Ritchie

Assignment

Log into riely373.cdm.depaul.edu (as shown in the lecture notes) and copy file hw1.c from /home/prof/public/ to the directory of your choice. For example:
cp /home/prof/public/hw1.c .
Then open the file hw1.c using an editor and complete the below assignment. Submit completed file hw1.c in COL.

1.    Implement function ranges that takes no input and prints the ranges (i.e., the minimum and maximum legal values) of integer types char, short, int, long, and long long, both signed and unsigned. You should do this by printing appropriate constants defined in header file <limit.h> located in directory /usr/include. Your output should be similar to:
signed char
minimum value: -128
maximum value: 127

unsigned char
minimum value: 0
maximum value: 255

signed short
minimum value: -32768
maximum value: 32767

... (and so on)
Note: The conversion instructions for signed and unsigned long are li and lu, respectively. The conversion instructions for signed and unsigned long long are lli and llu, respectively.


2. Implement the factorial function in three different ways: using a for loop in factorial1, using a while loop in factorial2, and using a do-while loop in factorial3. Your output for the included test code should be:
factorial1(10) = 3628800
factorial2(10) = 3628800
factorial3(10) = 3628800

3.    Implement function types that takes no input, declares 3 variables of type char, 3 of type short, 3 of type int, and 3 of type double---in that order---and prints the addresses of the 12 variables---in the same order---in both hex (use %p conversion instruction) and unsigned int format. Ignore the compilation warnings.
&a1 = 0xbff0fb2f, 3220241199
&a2 = 0xbff0fb2e, 3220241198
&a3 = 0xbff0fb2d, 3220241197
&b1 = 0xbff0fb2a, 3220241194
...