Assignment 6 - Your First C Program

A Simple C Program

Write a C program that does the following:

Additional Requirements:

Turn-In Requirements (Bitbucket)


How to create a C project in CCS

You'll create the project the same way you create an assembly project, but under "Project templates and examples" you'll select "Empty project (with main.c)". The shortcut to build is still Ctrl+B. The shortcut to debug is still F11.

Compiler Optimization Issue

There's a good chance you'll run into a warning that says "variable XXXX was set but never used".

The compiler is seeing that you've created a variable and potentially set it to different values, but never tested the value or assigned it to another variable. As far as the compiler is concerned, this code is useless - and it will delete it upon compilation. It views this as an improvement - your program now does the same thing with less code.

Usually, this is the behavior we want. In learning situations like this, we want to keep the compiler from making these sorts of optimizations. There are two ways we can accomplish this.

Using the Debugger with C

When programming in C, you'll want to monitor variables when you're debuggig. If you don't have a variables tab, go to View -> Variables. Now, a list of your program variables should be visible.

Sometimes it useful to look at variables in different bases. Maybe you want to see the value of a char as an ASCII character or as a hex value. To change the base your variable is shown in, right-click on the variables, select Number Format and choose a new format.