CS-220, Sections 50, 51
Laboratory Exercise 4
2-23-06, Lab Report due 3-2-06

In this lab you will learn to use the CC386 C Language Compiler System. This system is 
installed on all the public computers in the Academic A building, including the ones 
in the CS-220 Laboratory. You will also write, compile, and execute your first C 
Language programs for this course using the CC386 system. 

CC386 is a free product written by David Lindauer, available at
http://members.tripod.com/~ladsoft/. If you want to install the system on your home 
computer, the following is the procedure that you need to follow:

1. Download the compiler and associated files (1256KB), and put them into a directory, 
for example C:\cc386:
   A. Go to http://members.tripod.com/~ladsoft/
   B. In the left window pane click on 386 C Compiler
   C. In the left window pane click on DOS/DPMI and save it in the new C:\cc386 folder

2. Unzip all the downloaded files:
   Double click on ccdl293e.zip and extract all the files, specifying that the 
   extracted files should be put in the C:\cc386 directory

3. From a DOS command window, go to the C:\cc386 directory and type install c:
   Reply Y when you see the question do you want install to modify the path?

To use the compiler you need to get into a DOS Command Window and go to the directory
you will be working from (for example A: if you're using a floppy disk or C:\TEMP 
if you'll be working from that temporary directory on the computer's C drive). The 
following commands should then be typed in: 

set ladsoft=c:\cc386  
set path=c:\cc386\bin;c:\windows;c:\windows\system

You might want to use Notepad or some other editor to create a "batch" file that 
contains these two lines since every time you start the system you need to have 
those commands execute. If you do, you could call the file setpath.bat and put it 
into the directory you'll be working from. Then each time you start a new DOS 
Command Window, you would just need to type in 'setpath' from your working directory.

The CC386 system comes with extensive documentation and several example programs. 
You are encouraged to take a look at these. The documentation is in the directory 
c:\cc386\english and the examples are in c:\cc386\examples and c:\cc386\examples\dos.

To compile and link a program you have written in C (for example addsimp.c) with 
the CC386 system, you can type in the following command from the DOS prompt: 

cl386 +l addsimp.c

This command will try to invoke the CC386 C compiler, and if successful will 
generate the file addsimp.obj (the machine language translation). The +l 
switch causes the file addsimp.lst (a human-readable file containing the source 
C code and the machine language code generated as well as assembly language code that 
corresponds to the each machine language instruction) to be produced. The VALX linker 
will then be invoked to link in object code needed to generate the final addsimp.exe 
executable. If in the process there are any errors a file addsimp.err will be 
produced. This will give information on where the errors are and what caused them.

Part 1

In this part of the lab you are to use the CC386 system to compile the addsimp.c 
program given below. This program just adds two numbers and displays the sum on 
the screen. You should show the lab instructor that the program compiled successfully 
and runs. You should print out the .LST file and make a notes on it indicating what the 
underlying Pentium processor is actually doing as the program runs. In other words, 
what registers are being used to hold the variables and what assembly language 
instructions are being used to add them.

Part 2

Write a C language program that will display your name on the DOS Window screen when 
it is compiled and run. Be sure to save the source code as a file having a .c extension. 
(In other words, if, for example, you're working from Notepad and you want your program 
to be saved under the file name p2.c, be sure when you use "File | Save As" that you 
type the file name inside quotes ("p2.c") in the "File name:" combo box that appears in 
the "Save As" dialog box.

Part 3

Write a C language program that prompts the user to enter two decimal integers and 
then compute and displays on the screen the sum and the difference between the two 
numbers. (You will need to use the C Standard I/O function scanf(...) in this 

Part 4

Write a C language program that will do the same thing that the assembly language 
program you wrote in Part 2 of last week's lab did. The program should prompt the 
user to enter the values of a, b, c, and x; then it should perform the computation; 
finally it should display the result, the value of y, on the screen.

Part 5

Write a C language program that will do the same things as the assembly language 
program from Part 3 of last week's lab did. Once again the program should prompt the 
user for an intensity value (I1) and then extract and display the corresponding R1, 
G1, and B1 vlaues. Then it should prompt the user for red, green and blue values (R2, 
G2, B2) and compute and display the corresponding Intensity (I2) value. All values 
should be expressed in decimal. (Hint: use char (8-bit) variables to hold R, G, B 
values and int variables to hold Intensity values. You may have to use C language 
Boolean AND (&) and Boolean OR (|) as well as left-shift (<<) and right-shift (>>) 
operators. Also, if at any point you are attempting to assign part of an int variable 
to a byte-size char variable, you will need to use type casting. For example 
R = (char)I * 2;)

Lab Report

You should submit printed copies of the .LST files from all parts of this lab with 
comments written on them that explain what is happening at the machine/assembly 
language level as these programs run. You should also submit a diskette or a CD-ROM 
containing all the files created by you (and your editor program) and by the compiler 
in this lab; in particular, the .EXE files so the Lab Instructor can run them to 
determine whether they execute correctly.


/*** addsimp.c - Adds 5 and 3    ***/
/*** and displays the sum        ***/
/*** Programmer: R Eckert        ***/
/*** CS220, Section 50, 2-18-06  ***/

#include <stdio.h>

int main()
   int a=5;          /* the variables */
   int b=3;
   int c;
   c = a + b;        /* compute the sum */
   printf ("%d", c); /* display the sum */
   return (0);