### What does a computer program contain ?

• Important reminder: binary, binary, binary !!!

• Very important fact:

 Every thing stored inside a computer is stored as a binary number

• Note:

 Sometimes, I will use decimal numbers to depict the data stored inside the computer for convinience (Because we (= humans) can interpret decimal numbers more easily than binary numbers) You must always remember that these decimal numbers are actually binary numbers inside the computer (I.e.: if you want to know what is stored inside the computer, you must convert the decimal number into a binary number !!!)

• Computer program

• From CS170, you know that a computer program consists of:

• Variables

 Variable = memory cells used to record (= store) values

• Statements

 Statements are instructions (= commands) to tell the computer to perform some operation These instructions are stored in computer memory cells

• Storing a computer program inside the computer memort (RAM)

• A program stored in computer memory will look like this:

Explanation:

 The computer (program) instructions are stored at the start of the computer memory (RAM) Some variables are stored after the program instructions Some variables are stored at the end of the computer memory

Note:

• Different kinds of variables are stored in different ways in the computer memory (RAM) for management efficiency reasons

 Class variables are stored after the program instructions Local and parameter variables are stored at the end of the memory (in a stack)

We will explain this in more details later in this course

• Summary

• How is a program stored inside the computer (memory):

• A computer program stored in computer memory consist of:

Content of the memory cells:

1. Some memory cells contain computer instructions

(and the computer instructions are encoded as a binary number)

2. Some memory cells are used to store the values in a variable defined in the computer program

(and the value of the variable is encoded using the representation system of the variable's data type:

 The value is encoded in 2's complement code if the variable type is int, short or byte The value is encoded in IEEE 754 code if the variable type is double or float The value is encoded in ASCII code if the variable type is char

)

3. Some memory cells are unused

• Very important:

• The computer system knows:

 Which memory cells are used Which memory cells are unused !!!!

(So when the program creates a new variable, the computer system will use some unused memory cells to store the value of the new variable)