ECE 161: Programming Languages

Fall 2005

Monday 5:00 - 6:00 Rm 643E, Wednesday 3:00 - 5:00 Rm 621E

Click here for main page of course...

Topic #1: Structured Programming, Memory, and Activation Records

This topic covers some of the concepts that are important to virtually all programming languages.

We start with a review of basic C, including variables, if statements, loops, arrays, and functions. The Tic-Tac-Toe program is used to examine the C notations for all of these.

The concept of structured programming and the related notion of top-down design are discussed. Structured programming is one of the reasons that functions are so important, with other reasons being code reuse, code sharing, and data management.

We discuss machine code and the role of compilers. C is a compiled languages, as are most common languages used today. Certain languages are interpreted languages (e.g. Visual Basic and sometimes Java).

We discuss how variables are stored in memory, introducing the concepts of binary and hexadecimal numbers and how to convert numbers from one base to another. We determine that the number of bits used to represent a variable determines the range of values that the variable can have. Two's complement is usually used to represent negative integers. The IEEE standard is used to store floating-point numbers.

The bitwise operators (|, &, ^, ~, <<, >>) are described. A right shift may not do exactly what you expect when dealing with negative integers. Shifting bits of binary integers is equivalent to (but faster than) multiplying or dividing by powers of two. Compilers often make use of this fact.

ASCII is a common notation for representing character values.

The way that arrays (one-dimensional and two-dimensional) are stored in memory is discussed.

The way that an executing program uses memory (RAM) is discussed. Static memory stores code and globals. A stack is used for activations records which are discussed. Included in activation records is space for parameters and a return value, space for machine status information that needs to be restored when a function returns, and storage space for local variables and temporary variables. Programs also use a heap for dynamic memory allocation.

Computers also use registers for quick access to values. Swapping must often take place between values in memory and values in registers. This is all handled by a compiler.